yasserrmd commited on
Commit
3532724
·
verified ·
1 Parent(s): ef7c222

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
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
- # 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):
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