Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import threading
|
|
5 |
from datetime import datetime
|
6 |
from typing import List, Dict, Any, Generator
|
7 |
from session_manager import SessionManager
|
8 |
-
import
|
9 |
|
10 |
# Initialize session manager and get HF API key
|
11 |
session_manager = SessionManager()
|
@@ -72,11 +72,13 @@ def query_model(model_name: str, messages: List[Dict[str, str]]) -> str:
|
|
72 |
result = result.replace('**', '').replace('##', '') # Remove markdown
|
73 |
|
74 |
# Detect and format LaTeX content
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
80 |
result = result.strip() # Remove leading/trailing whitespace
|
81 |
return result # Return complete response
|
82 |
except Exception as e:
|
@@ -149,18 +151,19 @@ def respond(message: str, history: List[List[str]], session_id: str) -> Generato
|
|
149 |
# Create the Gradio interface with LaTeX support
|
150 |
with gr.Blocks() as demo:
|
151 |
gr.Markdown("## Multi-LLM Collaboration Chat")
|
152 |
-
# Add
|
153 |
demo.css = """
|
154 |
-
.
|
155 |
"""
|
156 |
demo.js = """
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
164 |
"""
|
165 |
|
166 |
with gr.Row():
|
|
|
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()
|
|
|
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:
|
|
|
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():
|