newtechdevng commited on
Commit
8731577
Β·
verified Β·
1 Parent(s): e083b3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -26
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 msg in history:
24
- messages.append({"role": msg["role"], "content": msg["content"]})
 
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.append({"role": "user", "content": question})
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", variant="secondary")
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 = question,
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(respond_tuple, [question, chatbot], [question, chatbot])
106
- question.submit(respond_tuple, [question, chatbot], [question, chatbot])
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())