Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -178,14 +178,14 @@ def layoutjson2md(image: Image.Image, layout_data: List[Dict], text_key: str = '
|
|
178 |
buffer = BytesIO()
|
179 |
cropped_img.save(buffer, format='PNG')
|
180 |
img_data = base64.b64encode(buffer.getvalue()).decode()
|
181 |
-
markdown_lines.append(f"
|
182 |
else:
|
183 |
-
markdown_lines.append("
|
184 |
except Exception as e:
|
185 |
print(f"Error processing image region: {e}")
|
186 |
-
markdown_lines.append("
|
187 |
else:
|
188 |
-
markdown_lines.append("
|
189 |
elif not text:
|
190 |
continue
|
191 |
elif category == 'Title':
|
@@ -203,7 +203,7 @@ def layoutjson2md(image: Image.Image, layout_data: List[Dict], text_key: str = '
|
|
203 |
markdown_lines.append(f"**Table:** {text}\n")
|
204 |
elif category == 'Formula':
|
205 |
if text.strip().startswith('$') or '\\' in text:
|
206 |
-
markdown_lines.append(f"
|
207 |
else:
|
208 |
markdown_lines.append(f"**Formula:** {text}\n")
|
209 |
elif category == 'Caption':
|
@@ -220,6 +220,7 @@ def layoutjson2md(image: Image.Image, layout_data: List[Dict], text_key: str = '
|
|
220 |
return str(layout_data)
|
221 |
return "\n".join(markdown_lines)
|
222 |
|
|
|
223 |
@spaces.GPU
|
224 |
def inference(model_name: str, image: Image.Image, text: str, max_new_tokens: int = 1024) -> str:
|
225 |
try:
|
|
|
178 |
buffer = BytesIO()
|
179 |
cropped_img.save(buffer, format='PNG')
|
180 |
img_data = base64.b64encode(buffer.getvalue()).decode()
|
181 |
+
markdown_lines.append(f"\n")
|
182 |
else:
|
183 |
+
markdown_lines.append("\n")
|
184 |
except Exception as e:
|
185 |
print(f"Error processing image region: {e}")
|
186 |
+
markdown_lines.append("\n")
|
187 |
else:
|
188 |
+
markdown_lines.append("\n")
|
189 |
elif not text:
|
190 |
continue
|
191 |
elif category == 'Title':
|
|
|
203 |
markdown_lines.append(f"**Table:** {text}\n")
|
204 |
elif category == 'Formula':
|
205 |
if text.strip().startswith('$') or '\\' in text:
|
206 |
+
markdown_lines.append(f"$$\n{text}\n$$\n")
|
207 |
else:
|
208 |
markdown_lines.append(f"**Formula:** {text}\n")
|
209 |
elif category == 'Caption':
|
|
|
220 |
return str(layout_data)
|
221 |
return "\n".join(markdown_lines)
|
222 |
|
223 |
+
|
224 |
@spaces.GPU
|
225 |
def inference(model_name: str, image: Image.Image, text: str, max_new_tokens: int = 1024) -> str:
|
226 |
try:
|