in hugging face space based on Gradio I need to make IDE, Editor, Compiler, Interpreter…
Private research annotation
Sign in to add a private research label or note.
- User
in hugging face space based on Gradio
I need to make IDE, Editor, Compiler, Interpreter
Should you use Python sandbox or not? I dont know.
You just need to make IDE, Editor, Compiler, Interpreter of Python
send me app.py and requirements.txt
start code: import gradio as gr import subprocess import io import sys
def execute_code(code, language, inputs): try: if language == "Python": old_stdout = sys.stdout new_stdout = io.StringIO() sys.stdout = new_stdout for input_str in inputs.split(','): input_str = input_str.strip() if '=' in input_str: var, value = input_str.split('=') exec(f"{var} = {value}") exec(code) output = new_stdout.getvalue() sys.stdout = old_stdout return f"Output: {output}\nErrors: None" elif language == "Bash": for input_str in inputs.split(','): input_str = input_str.strip() if '=' in input_str: var, value = input_str.split('=') code = code.replace(var, value) output = subprocess.check_output(code, shell=True).decode("utf-8") return f"Output: {output}\nErrors: None" else: return "Output: None\nErrors: Invalid language" except Exception as e: return f"Output: None\nErrors: {str(e)}"
demo = gr.Interface( fn=execute_code, inputs=[ gr.Textbox(label="Code", placeholder="Enter your code here"), gr.Dropdown(label="Language", choices=["Python", "Bash"], value="Python"), gr.Textbox(label="Inputs", placeholder="Enter your inputs here, separated by commas (e.g., x=5, y=10)"), ], outputs="text", title="Code Interpreter", description="Enter your code, select a language, and enter your inputs here", ) demo.launch()
- Assistant