staghado commited on
Commit
fc55e1f
·
verified ·
1 Parent(s): d5a7e96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -22,6 +22,16 @@ def image_to_base64(image):
22
  return base64.b64encode(buffered.getvalue()).decode("utf-8")
23
 
24
 
 
 
 
 
 
 
 
 
 
 
25
  def process_image(image, temperature):
26
  """
27
  Send image to vLLM endpoint and stream the response.
@@ -76,7 +86,9 @@ def process_image(image, temperature):
76
  content = delta.get('content', '')
77
  if content:
78
  accumulated_response += content
79
- yield accumulated_response, accumulated_response
 
 
80
  except json.JSONDecodeError:
81
  continue
82
 
 
22
  return base64.b64encode(buffered.getvalue()).decode("utf-8")
23
 
24
 
25
+ def convert_latex_delimiters(text):
26
+ """Convert [ ... ] LaTeX delimiters to $ ... $ for Gradio rendering."""
27
+ import re
28
+
29
+ # Replace display math: [ ... ] -> $ ... $
30
+ text = re.sub(r'\[\s*(.*?)\s*\]', r'$\1$', text, flags=re.DOTALL)
31
+
32
+ return text
33
+
34
+
35
  def process_image(image, temperature):
36
  """
37
  Send image to vLLM endpoint and stream the response.
 
86
  content = delta.get('content', '')
87
  if content:
88
  accumulated_response += content
89
+ # Convert LaTeX for rendered view, keep original for raw
90
+ rendered_text = convert_latex_delimiters(accumulated_response)
91
+ yield rendered_text, accumulated_response
92
  except json.JSONDecodeError:
93
  continue
94