Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,29 +16,32 @@ def respond(user_message, history):
|
|
16 |
if not user_message:
|
17 |
return "", history
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
],
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
|
33 |
history.append((user_message, assistant_reply))
|
34 |
|
35 |
return "", history
|
36 |
|
37 |
-
# ✅ **
|
38 |
with gr.Blocks() as demo:
|
39 |
-
gr.Markdown("
|
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 |
-
|
58 |
-
<script
|
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 |
"""
|