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 ["", ""] | |
else: | |
op = exec(source) | |
consoleop = sys.stdout.getvalue().strip() | |
return [op, consoleop] | |
except Exception as e: | |
return ["", f"{e}"] | |
sys.stdout = original_stdout | |
app = gr.Interface( | |
fn=exc, | |
inputs=["text", "text"], | |
outputs=["text", "text"], | |
) | |
app.launch() |