Spaces:
Sleeping
Sleeping
Update app.py
Browse files15 unmodified lines16171819192021222324252021222324252627282927282930313031323334353637383937404139404243444546479 unmodified lines5758595758606162606364656615 unmodified lines if not user_message: return "", history
try: assistant_reply = client.chat.completions.create( model="gpt-4o", messages=[ {"role": "system", "content": MAIN_PROMPT}, *[ {"role": "user", "content": u} if i % 2 == 0 else {"role": "assistant", "content": a} for i, (u, a) in enumerate(history) assistant_reply = client.chat.completions.create( model="gpt-4o", messages=[ {"role": "system", "content": MAIN_PROMPT}, *[ {"role": "user", "content": u} if i % 2 == 0 else {"role": "assistant", "content": a} for i, (u, a) in enumerate(history) ], {"role": "user", "content": user_message} ], {"role": "user", "content": user_message} ], max_tokens=512, temperature=0.7, ).choices[0].message.content max_tokens=512, temperature=0.7, ).choices[0].message.content except Exception as e: assistant_reply = f"Error: {str(e)}"
history.append((user_message, assistant_reply))
return "", history
# ✅ **Explicitly enable MathJax for LaTeX rendering**# ✅ **Ensure MathJax is Enabled for LaTeX Rendering**with gr.Blocks() as demo: gr.Markdown("## AI-Guided Math PD Chatbot") chatbot = gr.Chatbot(height=500) gr.Markdown("# AI-Guided Math PD Chatbot")
chatbot = gr.Chatbot(height=500) state_history = gr.State([("", MAIN_PROMPT)])
user_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")9 unmodified lines )
gr.Markdown( r""" <script type="text/javascript"> """ <script> MathJax = { tex: { inlineMath: [['$', '$'], ['\\(', '\\)']] } tex: { inlineMath: [['$', '$'], ['\\(', '\\)']], displayMath: [['$$', '$$']] } }; </script> """app.py+21-18