Spaces:
Sleeping
Sleeping
Update app.py
Browse files15 unmodified lines16171819202122232425262728293031323334353637383940414243449 unmodified lines5455565758596061626315 unmodified linesif not user_message:return "", historyassistant_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}],max_tokens=512,temperature=0.7,).choices[0].message.contenthistory.append((user_message, assistant_reply))return "", history# ✅ **Explicitly enable MathJax for LaTeX rendering**with gr.Blocks() as demo: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">MathJax = {tex: { inlineMath: [['$', '$'], ['\\(', '\\)']] }};</script>"""15 unmodified lines16171819202122232425262728293031323334353637383940414243444546479 unmodified lines5758596061626364656615 unmodified linesif not user_message:return "", historytry: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}],max_tokens=512,temperature=0.7,).choices[0].message.contentexcept Exception as e:assistant_reply = f"Error: {str(e)}"history.append((user_message, assistant_reply))return "", history# ✅ **Ensure MathJax is Enabled for LaTeX Rendering**with gr.Blocks() as demo: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("""<script>MathJax = {tex: { inlineMath: [['$', '$'], ['\\(', '\\)']], displayMath: [['$$', '$$']] }};</script>"""
app.py+21-18