Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,24 +9,20 @@ client = InferenceClient()
|
|
9 |
|
10 |
|
11 |
def preprocess_latex(content):
|
12 |
-
#
|
13 |
-
lines = content.split("\n")
|
14 |
processed_lines = []
|
15 |
-
|
16 |
for line in lines:
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
processed_lines.append(line) # Fallback to raw line if parsing fails
|
24 |
-
elif "(" in line and ")" in line: # Treat as inline math
|
25 |
-
processed_lines.append(line.replace("(", "$").replace(")", "$"))
|
26 |
else:
|
27 |
-
processed_lines.append(line) # Plain text remains
|
28 |
|
29 |
-
return "\n".join(processed_lines)
|
30 |
|
31 |
# Function to generate and format AI response
|
32 |
def generate_response(prompt_template, **kwargs):
|
|
|
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 |
+
# Identify and format block math
|
17 |
+
if "[" in line and "]" in line: # Treat as block math
|
18 |
+
math_expr = line[line.index("[") + 1:line.index("]")] # Extract the math inside brackets
|
19 |
+
processed_lines.append(f"$$ {math_expr.strip()} $$")
|
20 |
+
elif "$" in line: # Inline math expressions
|
21 |
+
processed_lines.append(line) # Inline math is already wrapped
|
|
|
|
|
|
|
22 |
else:
|
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):
|