Khoi1234210 commited on
Commit
b8dcaff
·
verified ·
1 Parent(s): 76dba01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -102,7 +102,7 @@ def create_math_system_message():
102
  Be clear, precise, and educational."""
103
 
104
  def render_latex(text):
105
- """Clean and normalize LaTeX"""
106
  if not text:
107
  return text
108
 
@@ -119,6 +119,9 @@ def render_latex(text):
119
  # Remove duplicate $$
120
  text = re.sub(r'\$\$+', '$$', text)
121
 
 
 
 
122
  return text
123
 
124
  def try_sympy_compute(message):
@@ -208,10 +211,22 @@ def get_random_sample():
208
  return random.choice(math_samples)
209
 
210
  # Gradio Interface
211
- with gr.Blocks(title="🧮 Mathetics AI", theme=gr.themes.Soft()) as demo:
 
 
 
212
  gr.Markdown("# 🧮 **Mathetics AI**\n*Advanced Math Tutor powered by Qwen2.5-Math*")
213
 
214
- chatbot = gr.Chatbot(height=500, type='messages', label="💬 Conversation")
 
 
 
 
 
 
 
 
 
215
  msg = gr.Textbox(placeholder="Ask any math problem...", show_label=False, scale=4)
216
 
217
  with gr.Row():
 
102
  Be clear, precise, and educational."""
103
 
104
  def render_latex(text):
105
+ """Clean and normalize LaTeX for proper rendering"""
106
  if not text:
107
  return text
108
 
 
119
  # Remove duplicate $$
120
  text = re.sub(r'\$\$+', '$$', text)
121
 
122
+ # Escape backslashes for proper rendering in Gradio
123
+ text = text.replace('\\\\', '\\')
124
+
125
  return text
126
 
127
  def try_sympy_compute(message):
 
211
  return random.choice(math_samples)
212
 
213
  # Gradio Interface
214
+ with gr.Blocks(title="🧮 Mathetics AI", theme=gr.themes.Soft(), css="""
215
+ .katex { font-size: 1.1em; }
216
+ .katex-display { margin: 1em 0; }
217
+ """) as demo:
218
  gr.Markdown("# 🧮 **Mathetics AI**\n*Advanced Math Tutor powered by Qwen2.5-Math*")
219
 
220
+ chatbot = gr.Chatbot(
221
+ height=500,
222
+ type='messages',
223
+ label="💬 Conversation",
224
+ latex_delimiters=[
225
+ {"left": "$$", "right": "$$", "display": True},
226
+ {"left": "$", "right": "$", "display": False}
227
+ ],
228
+ show_copy_button=True
229
+ )
230
  msg = gr.Textbox(placeholder="Ask any math problem...", show_label=False, scale=4)
231
 
232
  with gr.Row():