Tonic commited on
Commit
63a03ad
β€’
1 Parent(s): 17cf082

return formatted res

Browse files
Files changed (2) hide show
  1. app.py +6 -3
  2. globe.py +1 -0
app.py CHANGED
@@ -15,6 +15,7 @@ import tempfile
15
  import time
16
  import shutil
17
  import cv2
 
18
 
19
 
20
  model_name = 'ucaslcl/GOT-OCR2_0'
@@ -138,15 +139,17 @@ def ocr_demo(image, task, ocr_type, ocr_box, ocr_color):
138
  return res, None
139
 
140
  res = res.replace("\\title", "\\title ")
141
- res = f"$$ {res} $$"
 
 
142
 
143
  if html_content:
144
  encoded_html = base64.b64encode(html_content.encode('utf-8')).decode('utf-8')
145
  iframe_src = f"data:text/html;base64,{encoded_html}"
146
  iframe = f'<iframe src="{iframe_src}" width="100%" height="600px"></iframe>'
147
  download_link = f'<a href="data:text/html;base64,{encoded_html}" download="result_{unique_id}.html">Download Full Result</a>'
148
- return res, f"{download_link}<br>{iframe}"
149
- return res, None
150
 
151
  def cleanup_old_files():
152
  current_time = time.time()
 
15
  import time
16
  import shutil
17
  import cv2
18
+ import re
19
 
20
 
21
  model_name = 'ucaslcl/GOT-OCR2_0'
 
139
  return res, None
140
 
141
  res = res.replace("\\title", "\\title ")
142
+ lines = re.split(r'\\\\', res) # Split on double backslashes
143
+ formatted_lines = [f"$$ {line.strip()} $$" for line in lines if line.strip()]
144
+ formatted_res = "\n".join(formatted_lines)
145
 
146
  if html_content:
147
  encoded_html = base64.b64encode(html_content.encode('utf-8')).decode('utf-8')
148
  iframe_src = f"data:text/html;base64,{encoded_html}"
149
  iframe = f'<iframe src="{iframe_src}" width="100%" height="600px"></iframe>'
150
  download_link = f'<a href="data:text/html;base64,{encoded_html}" download="result_{unique_id}.html">Download Full Result</a>'
151
+ return formatted_res, f"{download_link}<br>{iframe}"
152
+ return formatted_res, None
153
 
154
  def cleanup_old_files():
155
  current_time = time.time()
globe.py CHANGED
@@ -40,6 +40,7 @@ modelinfor = """
40
  - **Model Name**: GOT-OCR 2.0
41
  - **Hugging Face Repository**: [ucaslcl/GOT-OCR2_0](https://huggingface.co/ucaslcl/GOT-OCR2_0)
42
  - **Environment**: CUDA 11.8 + PyTorch 2.0.1
 
43
  """
44
 
45
  tasks = [
 
40
  - **Model Name**: GOT-OCR 2.0
41
  - **Hugging Face Repository**: [ucaslcl/GOT-OCR2_0](https://huggingface.co/ucaslcl/GOT-OCR2_0)
42
  - **Environment**: CUDA 11.8 + PyTorch 2.0.1
43
+
44
  """
45
 
46
  tasks = [