python / app.py
xcx0902's picture
Create app.py
4338994 verified
raw
history blame
361 Bytes
import gradio as gr
import io
import sys
def run(code):
old_stdout = sys.stdout
sys.stdout = buffer = io.StringIO()
try:
exec(code, {})
except Exception as e:
print(f"Error: {e}")
finally:
sys.stdout = old_stdout
return buffer.getvalue()
demo = gr.Interface(fn=run, inputs="text", outputs="text")
demo.launch()