Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,21 +9,23 @@ client = InferenceClient()
|
|
| 9 |
|
| 10 |
|
| 11 |
def preprocess_latex(content):
|
|
|
|
| 12 |
lines = content.split("\n") # Split response into lines
|
| 13 |
processed_lines = []
|
| 14 |
|
| 15 |
for line in lines:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
processed_lines.append(line) # Plain text remains unchanged
|
| 24 |
|
| 25 |
return "\n".join(processed_lines) # Join lines back into a single string
|
| 26 |
|
|
|
|
|
|
|
| 27 |
# Function to generate and format AI response
|
| 28 |
def generate_response(prompt_template, **kwargs):
|
| 29 |
# Simulate processing/loading
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def preprocess_latex(content):
|
| 12 |
+
"""Preprocess the AI response to format LaTeX properly."""
|
| 13 |
lines = content.split("\n") # Split response into lines
|
| 14 |
processed_lines = []
|
| 15 |
|
| 16 |
for line in lines:
|
| 17 |
+
if "[" in line and "]" in line: # Detect math expressions in brackets
|
| 18 |
+
while "[" in line and "]" in line:
|
| 19 |
+
start = line.index("[")
|
| 20 |
+
end = line.index("]") + 1
|
| 21 |
+
math_expr = line[start:end].strip("[]").strip()
|
| 22 |
+
line = line[:start] + f"$$ {math_expr} $$" + line[end:]
|
| 23 |
+
processed_lines.append(line)
|
|
|
|
| 24 |
|
| 25 |
return "\n".join(processed_lines) # Join lines back into a single string
|
| 26 |
|
| 27 |
+
|
| 28 |
+
|
| 29 |
# Function to generate and format AI response
|
| 30 |
def generate_response(prompt_template, **kwargs):
|
| 31 |
# Simulate processing/loading
|