Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# Define the main chat response function.
|
| 4 |
+
def chat_response(user_input):
|
| 5 |
+
# Your chat response logic here.
|
| 6 |
+
return "Hello, I am a chatbot. How can I help you?"
|
| 7 |
+
|
| 8 |
+
# Create the Gradio interface.
|
| 9 |
+
iface = gr.Interface(
|
| 10 |
+
fn=chat_response,
|
| 11 |
+
inputs=gr.Textbox(label="User Input"),
|
| 12 |
+
outputs=gr.Textbox(label="Chatbot Response"),
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Add the code editor and debug screen.
|
| 16 |
+
code_editor = gr.CodeEditor(label="Code Editor")
|
| 17 |
+
debug_screen = gr.Textbox(label="Debug Screen")
|
| 18 |
+
|
| 19 |
+
# Define the function to execute the Python code.
|
| 20 |
+
def execute_code(code):
|
| 21 |
+
try:
|
| 22 |
+
# Execute the code and capture the output.
|
| 23 |
+
output = eval(code)
|
| 24 |
+
debug_screen.update(f"Code executed successfully.\nOutput: {output}")
|
| 25 |
+
except Exception as e:
|
| 26 |
+
debug_screen.update(f"Error executing code: {e}")
|
| 27 |
+
|
| 28 |
+
# Create the Gradio interface for the code execution.
|
| 29 |
+
code_execution_iface = gr.Interface(
|
| 30 |
+
fn=execute_code,
|
| 31 |
+
inputs=code_editor,
|
| 32 |
+
outputs=debug_screen,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Add the screens to the main interface.
|
| 36 |
+
iface.add_examples(
|
| 37 |
+
[
|
| 38 |
+
("What is the capital of France?", "Paris"),
|
| 39 |
+
("What is the square root of 16?", 4),
|
| 40 |
+
]
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# Launch the Gradio interface.
|
| 44 |
+
iface.launch()
|