Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import sys
|
3 |
+
|
4 |
+
def execute_code(code):
|
5 |
+
try:
|
6 |
+
exec(code, globals())
|
7 |
+
return "Code executed successfully!"
|
8 |
+
except Exception as e:
|
9 |
+
return f"Error: {str(e)}"
|
10 |
+
|
11 |
+
code_input = gr.inputs.Textbox(lines=10, label="Enter Python code")
|
12 |
+
execute_button = gr.inputs.Button(text="Execute Code")
|
13 |
+
result_text = gr.outputs.Textbox(label="Execution Result")
|
14 |
+
|
15 |
+
def execute_code_callback(code):
|
16 |
+
return execute_code(code)
|
17 |
+
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=execute_code_callback,
|
20 |
+
inputs=[code_input, execute_button],
|
21 |
+
outputs=result_text,
|
22 |
+
title="Code Executor",
|
23 |
+
description="Enter your Python code and click 'Execute Code' to run it."
|
24 |
+
)
|
25 |
+
|
26 |
+
iface.launch()
|