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()