alibicer commited on
Commit
9e63e25
·
verified ·
1 Parent(s): b1ef7b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -18
app.py CHANGED
@@ -16,29 +16,32 @@ def respond(user_message, history):
16
  if not user_message:
17
  return "", history
18
 
19
- assistant_reply = client.chat.completions.create(
20
- model="gpt-4o",
21
- messages=[
22
- {"role": "system", "content": MAIN_PROMPT},
23
- *[
24
- {"role": "user", "content": u} if i % 2 == 0 else {"role": "assistant", "content": a}
25
- for i, (u, a) in enumerate(history)
 
 
 
26
  ],
27
- {"role": "user", "content": user_message}
28
- ],
29
- max_tokens=512,
30
- temperature=0.7,
31
- ).choices[0].message.content
32
 
33
  history.append((user_message, assistant_reply))
34
 
35
  return "", history
36
 
37
- # ✅ **Explicitly enable MathJax for LaTeX rendering**
38
  with gr.Blocks() as demo:
39
- gr.Markdown("## AI-Guided Math PD Chatbot")
40
- chatbot = gr.Chatbot(height=500)
41
 
 
42
  state_history = gr.State([("", MAIN_PROMPT)])
43
 
44
  user_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")
@@ -54,10 +57,10 @@ with gr.Blocks() as demo:
54
  )
55
 
56
  gr.Markdown(
57
- r"""
58
- <script type="text/javascript">
59
  MathJax = {
60
- tex: { inlineMath: [['$', '$'], ['\\(', '\\)']] }
61
  };
62
  </script>
63
  """
 
16
  if not user_message:
17
  return "", history
18
 
19
+ try:
20
+ assistant_reply = client.chat.completions.create(
21
+ model="gpt-4o",
22
+ messages=[
23
+ {"role": "system", "content": MAIN_PROMPT},
24
+ *[
25
+ {"role": "user", "content": u} if i % 2 == 0 else {"role": "assistant", "content": a}
26
+ for i, (u, a) in enumerate(history)
27
+ ],
28
+ {"role": "user", "content": user_message}
29
  ],
30
+ max_tokens=512,
31
+ temperature=0.7,
32
+ ).choices[0].message.content
33
+ except Exception as e:
34
+ assistant_reply = f"Error: {str(e)}"
35
 
36
  history.append((user_message, assistant_reply))
37
 
38
  return "", history
39
 
40
+ # ✅ **Ensure MathJax is Enabled for LaTeX Rendering**
41
  with gr.Blocks() as demo:
42
+ gr.Markdown("# AI-Guided Math PD Chatbot")
 
43
 
44
+ chatbot = gr.Chatbot(height=500)
45
  state_history = gr.State([("", MAIN_PROMPT)])
46
 
47
  user_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")
 
57
  )
58
 
59
  gr.Markdown(
60
+ """
61
+ <script>
62
  MathJax = {
63
+ tex: { inlineMath: [['$', '$'], ['\\(', '\\)']], displayMath: [['$$', '$$']] }
64
  };
65
  </script>
66
  """