Omega-02 commited on
Commit
5536629
·
verified ·
1 Parent(s): d1191fd

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +26 -0
main.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def run_code(code):
4
+ try:
5
+ # Execute the code in a separate namespace
6
+ namespace = {}
7
+ exec(code, namespace)
8
+ # Capture the output
9
+ output = namespace.get('output', None)
10
+ if output is None:
11
+ output = "No output captured."
12
+ except Exception as e:
13
+ output = f"Error: {str(e)}"
14
+ return output
15
+
16
+ # Define the Gradio interface
17
+ with gr.Blocks() as demo:
18
+ code_input = gr.Textbox(label="Enter Python Code", lines=10)
19
+ run_button = gr.Button("Run Code")
20
+ output_text = gr.Textbox(label="Output", lines=10)
21
+
22
+ # Define the event handler
23
+ run_button.click(fn=run_code, inputs=code_input, outputs=output_text)
24
+
25
+ # Launch the Gradio app
26
+ demo.launch()