Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,8 +20,9 @@ def solve(question, history):
|
|
| 20 |
messages = [
|
| 21 |
{"role": "system", "content": "You are a helpful math tutor. Solve problems step by step, showing all working clearly."},
|
| 22 |
]
|
| 23 |
-
for
|
| 24 |
-
messages.append({"role":
|
|
|
|
| 25 |
messages.append({"role": "user", "content": question})
|
| 26 |
|
| 27 |
text = tokenizer.apply_chat_template(
|
|
@@ -47,8 +48,7 @@ def respond(question, history):
|
|
| 47 |
if not question.strip():
|
| 48 |
return "", history
|
| 49 |
answer = solve(question, history)
|
| 50 |
-
history
|
| 51 |
-
history.append({"role": "assistant", "content": answer})
|
| 52 |
return "", history
|
| 53 |
|
| 54 |
# ββ UI βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -59,22 +59,17 @@ with gr.Blocks(title="Math Tutor AI") as demo:
|
|
| 59 |
---
|
| 60 |
""")
|
| 61 |
|
| 62 |
-
chatbot = gr.Chatbot(
|
| 63 |
-
height = 450,
|
| 64 |
-
label = "Math Tutor",
|
| 65 |
-
show_copy_button = True,
|
| 66 |
-
)
|
| 67 |
|
| 68 |
with gr.Row():
|
| 69 |
question = gr.Textbox(
|
| 70 |
placeholder = "Type your math question here...",
|
| 71 |
label = "Your Question",
|
| 72 |
-
lines = 1,
|
| 73 |
scale = 4,
|
| 74 |
)
|
| 75 |
submit = gr.Button("Solve β", variant="primary", scale=1)
|
| 76 |
|
| 77 |
-
clear = gr.Button("ποΈ Clear Chat"
|
| 78 |
|
| 79 |
gr.Examples(
|
| 80 |
label = "Try these examples:",
|
|
@@ -86,24 +81,13 @@ with gr.Blocks(title="Math Tutor AI") as demo:
|
|
| 86 |
"Find the compound interest on βΉ5000 at 10% per annum for 2 years.",
|
| 87 |
"Prove that β2 is irrational.",
|
| 88 |
],
|
| 89 |
-
inputs
|
| 90 |
)
|
| 91 |
|
| 92 |
-
gr.Markdown(""
|
| 93 |
-
---
|
| 94 |
-
*Model: Qwen2.5-Math-1.5B fine-tuned on 10K math problems*
|
| 95 |
-
""")
|
| 96 |
-
|
| 97 |
-
# ββ Event Handlers ββββββββββββββββββββββββββββββββββββββ
|
| 98 |
-
def respond_tuple(question, history):
|
| 99 |
-
if not question.strip():
|
| 100 |
-
return "", history
|
| 101 |
-
answer = solve(question, history)
|
| 102 |
-
history = history + [[question, answer]]
|
| 103 |
-
return "", history
|
| 104 |
|
| 105 |
-
submit.click(
|
| 106 |
-
question.submit(
|
| 107 |
clear.click(lambda: ([], ""), outputs=[chatbot, question])
|
| 108 |
|
| 109 |
demo.launch(theme=gr.themes.Soft())
|
|
|
|
| 20 |
messages = [
|
| 21 |
{"role": "system", "content": "You are a helpful math tutor. Solve problems step by step, showing all working clearly."},
|
| 22 |
]
|
| 23 |
+
for item in history:
|
| 24 |
+
messages.append({"role": "user", "content": item[0]})
|
| 25 |
+
messages.append({"role": "assistant", "content": item[1]})
|
| 26 |
messages.append({"role": "user", "content": question})
|
| 27 |
|
| 28 |
text = tokenizer.apply_chat_template(
|
|
|
|
| 48 |
if not question.strip():
|
| 49 |
return "", history
|
| 50 |
answer = solve(question, history)
|
| 51 |
+
history = history + [[question, answer]]
|
|
|
|
| 52 |
return "", history
|
| 53 |
|
| 54 |
# ββ UI βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 59 |
---
|
| 60 |
""")
|
| 61 |
|
| 62 |
+
chatbot = gr.Chatbot(height=450)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
with gr.Row():
|
| 65 |
question = gr.Textbox(
|
| 66 |
placeholder = "Type your math question here...",
|
| 67 |
label = "Your Question",
|
|
|
|
| 68 |
scale = 4,
|
| 69 |
)
|
| 70 |
submit = gr.Button("Solve β", variant="primary", scale=1)
|
| 71 |
|
| 72 |
+
clear = gr.Button("ποΈ Clear Chat")
|
| 73 |
|
| 74 |
gr.Examples(
|
| 75 |
label = "Try these examples:",
|
|
|
|
| 81 |
"Find the compound interest on βΉ5000 at 10% per annum for 2 years.",
|
| 82 |
"Prove that β2 is irrational.",
|
| 83 |
],
|
| 84 |
+
inputs = question,
|
| 85 |
)
|
| 86 |
|
| 87 |
+
gr.Markdown("*Model: Qwen2.5-Math-1.5B fine-tuned on 10K math problems*")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
submit.click(respond, [question, chatbot], [question, chatbot])
|
| 90 |
+
question.submit(respond, [question, chatbot], [question, chatbot])
|
| 91 |
clear.click(lambda: ([], ""), outputs=[chatbot, question])
|
| 92 |
|
| 93 |
demo.launch(theme=gr.themes.Soft())
|