Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import io
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
def run(code):
|
| 6 |
+
old_stdout = sys.stdout
|
| 7 |
+
sys.stdout = buffer = io.StringIO()
|
| 8 |
+
try:
|
| 9 |
+
exec(code, {})
|
| 10 |
+
except Exception as e:
|
| 11 |
+
print(f"Error: {e}")
|
| 12 |
+
finally:
|
| 13 |
+
sys.stdout = old_stdout
|
| 14 |
+
return buffer.getvalue()
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(fn=run, inputs="text", outputs="text")
|
| 17 |
+
demo.launch()
|