import gradio as gr from io import StringIO import sys import os original_stdout = sys.stdout sys.stdout = StringIO() def exc(source, token): sys.stdout = StringIO() try: if token != os.environ["special_token"]: return "Token Incorrect" else: op = exec(source) consoleop = sys.stdout.getvalue().strip() return f"""['''ExecOP: {op}''', '''ConsoleOP: {consoleop}''']""" except Exception as e: return f"{e}" sys.stdout = original_stdout app = gr.Interface( fn=exc, inputs=["text", "text"], outputs=["text"], ) app.launch()