luminoussg commited on
Commit
63f9ec0
Β·
verified Β·
1 Parent(s): 4234202

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -28
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
2
  import os
3
  import requests
 
4
  import threading
5
  from datetime import datetime
6
  from typing import List, Dict, Any, Generator
7
  from session_manager import SessionManager
8
- from sympy import latex, sympify
9
 
10
  # Initialize session manager and get HF API key
11
  session_manager = SessionManager()
@@ -67,18 +67,9 @@ def query_model(model_name: str, messages: List[Dict[str, str]]) -> str:
67
  response = requests.post(endpoint, json=payload, headers=headers)
68
  response.raise_for_status()
69
  result = response.json()[0]['generated_text']
70
- # Clean up response formatting and handle LaTeX
71
  result = result.split('<|')[0] # Remove any remaining special tokens
72
- result = result.replace('**', '').replace('##', '') # Remove markdown
73
-
74
- # Detect and format LaTeX content
75
- try:
76
- # Convert mathematical expressions to LaTeX
77
- result = latex(sympify(result, evaluate=False))
78
- result = f'<div class="math">{result}</div>'
79
- except:
80
- # If conversion fails, return the original text
81
- pass
82
  result = result.strip() # Remove leading/trailing whitespace
83
  return result # Return complete response
84
  except Exception as e:
@@ -148,29 +139,22 @@ def respond(message: str, history: List[List[str]], session_id: str) -> Generato
148
  # Return final combined response
149
  yield f"πŸ”΅ **Qwen2.5-Coder-32B-Instruct**\n{response1}\n\n🟣 **Qwen2.5-72B-Instruct**\n{response2}\n\n🟑 **Llama3.3-70B-Instruct**\n{response3}"
150
 
151
- # Create the Gradio interface with LaTeX support
152
  with gr.Blocks() as demo:
153
  gr.Markdown("## Multi-LLM Collaboration Chat")
154
- # Add MathJax configuration for LaTeX rendering
155
- demo.css = """
156
- .math { font-size: 1.1em; }
157
- """
158
- demo.js = """
159
- MathJax = {
160
- tex: {
161
- inlineMath: [['$', '$'], ['\\(', '\\)']]
162
- },
163
- svg: {
164
- fontCache: 'global'
165
- }
166
- };
167
- """
168
 
169
  with gr.Row():
170
  session_id = gr.State(session_manager.create_session)
171
  new_session = gr.Button("πŸ”„ New Session")
172
 
173
- chatbot = gr.Chatbot(height=600)
 
 
 
 
 
 
174
  msg = gr.Textbox(label="Message")
175
 
176
  def on_new_session():
 
1
  import gradio as gr
2
  import os
3
  import requests
4
+ import re
5
  import threading
6
  from datetime import datetime
7
  from typing import List, Dict, Any, Generator
8
  from session_manager import SessionManager
 
9
 
10
  # Initialize session manager and get HF API key
11
  session_manager = SessionManager()
 
67
  response = requests.post(endpoint, json=payload, headers=headers)
68
  response.raise_for_status()
69
  result = response.json()[0]['generated_text']
70
+ # Clean up response formatting
71
  result = result.split('<|')[0] # Remove any remaining special tokens
72
+ result = re.sub(r'\*\*|##', '', result) # Remove markdown bold/headers but preserve LaTeX
 
 
 
 
 
 
 
 
 
73
  result = result.strip() # Remove leading/trailing whitespace
74
  return result # Return complete response
75
  except Exception as e:
 
139
  # Return final combined response
140
  yield f"πŸ”΅ **Qwen2.5-Coder-32B-Instruct**\n{response1}\n\n🟣 **Qwen2.5-72B-Instruct**\n{response2}\n\n🟑 **Llama3.3-70B-Instruct**\n{response3}"
141
 
142
+ # Create the Gradio interface
143
  with gr.Blocks() as demo:
144
  gr.Markdown("## Multi-LLM Collaboration Chat")
145
+ gr.HTML("<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-mml-chtml.js' id='MathJax-script'></script>")
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  with gr.Row():
148
  session_id = gr.State(session_manager.create_session)
149
  new_session = gr.Button("πŸ”„ New Session")
150
 
151
+ chatbot = gr.Chatbot(
152
+ height=600,
153
+ latex_delimiters=[
154
+ {"left": "$$", "right": "$$", "display": True},
155
+ {"left": "$", "right": "$", "display": False}
156
+ ]
157
+ )
158
  msg = gr.Textbox(label="Message")
159
 
160
  def on_new_session():