Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import sys
|
|
| 4 |
import io
|
| 5 |
import traceback
|
| 6 |
|
|
|
|
| 7 |
model_name = "Qwen/Qwen2.5-72B-Instruct"
|
| 8 |
client = InferenceClient(model_name)
|
| 9 |
|
|
@@ -42,20 +43,42 @@ def execute_code(code):
|
|
| 42 |
sys.stdout = old_stdout
|
| 43 |
return output
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
gr.Markdown("# π Python Helper Chatbot")
|
| 47 |
with gr.Tab("Chat"):
|
| 48 |
chatbot = gr.Chatbot()
|
| 49 |
msg = gr.Textbox(placeholder="Type your message here...")
|
| 50 |
msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot, chatbot])
|
|
|
|
| 51 |
with gr.Tab("Interpreter"):
|
| 52 |
gr.Markdown("### π₯οΈ Test Your Code")
|
| 53 |
code_input = gr.Code(language="python")
|
| 54 |
run_button = gr.Button("Run Code")
|
| 55 |
code_output = gr.Textbox(label="Output")
|
| 56 |
run_button.click(execute_code, inputs=code_input, outputs=code_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
with gr.Tab("Logs"):
|
| 58 |
gr.Markdown("### π Logs")
|
| 59 |
log_output = gr.Textbox(label="Logs", lines=10, interactive=False)
|
| 60 |
|
|
|
|
| 61 |
demo.launch()
|
|
|
|
| 4 |
import io
|
| 5 |
import traceback
|
| 6 |
|
| 7 |
+
# Initialize the AI model
|
| 8 |
model_name = "Qwen/Qwen2.5-72B-Instruct"
|
| 9 |
client = InferenceClient(model_name)
|
| 10 |
|
|
|
|
| 43 |
sys.stdout = old_stdout
|
| 44 |
return output
|
| 45 |
|
| 46 |
+
def solve_math_task(math_task):
|
| 47 |
+
# Generate Python code for the math task
|
| 48 |
+
generated_code = llm_inference(f"Create a Python program to solve the following math problem:\n{math_task}")
|
| 49 |
+
|
| 50 |
+
# Execute the generated code
|
| 51 |
+
execution_result = execute_code(generated_code)
|
| 52 |
+
|
| 53 |
+
return generated_code, execution_result
|
| 54 |
+
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
gr.Markdown("# π Python Helper Chatbot")
|
| 57 |
with gr.Tab("Chat"):
|
| 58 |
chatbot = gr.Chatbot()
|
| 59 |
msg = gr.Textbox(placeholder="Type your message here...")
|
| 60 |
msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot, chatbot])
|
| 61 |
+
|
| 62 |
with gr.Tab("Interpreter"):
|
| 63 |
gr.Markdown("### π₯οΈ Test Your Code")
|
| 64 |
code_input = gr.Code(language="python")
|
| 65 |
run_button = gr.Button("Run Code")
|
| 66 |
code_output = gr.Textbox(label="Output")
|
| 67 |
run_button.click(execute_code, inputs=code_input, outputs=code_output)
|
| 68 |
+
|
| 69 |
+
with gr.Tab("Math Solver"):
|
| 70 |
+
gr.Markdown("### π Math Task Solver")
|
| 71 |
+
math_input = gr.Textbox(placeholder="Enter your mathematical task here...", lines=2)
|
| 72 |
+
solve_button = gr.Button("Solve Task")
|
| 73 |
+
with gr.Row():
|
| 74 |
+
generated_code_output = gr.Code(label="Generated Python Code", language="python")
|
| 75 |
+
with gr.Row():
|
| 76 |
+
execution_output = gr.Textbox(label="Execution Result", lines=10)
|
| 77 |
+
solve_button.click(solve_math_task, inputs=math_input, outputs=[generated_code_output, execution_output])
|
| 78 |
+
|
| 79 |
with gr.Tab("Logs"):
|
| 80 |
gr.Markdown("### π Logs")
|
| 81 |
log_output = gr.Textbox(label="Logs", lines=10, interactive=False)
|
| 82 |
|
| 83 |
+
# Launch the Gradio app
|
| 84 |
demo.launch()
|