Spaces:
Configuration error
Configuration error
add latex display
Browse files
app.py
CHANGED
|
@@ -53,16 +53,18 @@ def run_GOT(image, got_mode, fine_grained_mode="", ocr_color="", ocr_box=""):
|
|
| 53 |
elif got_mode == "format fine-grained OCR":
|
| 54 |
res = model.chat(tokenizer, image_path, ocr_type='format', ocr_box=ocr_box, ocr_color=ocr_color, render=True, save_render_file=result_path)
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
with open(result_path, 'r') as f:
|
| 58 |
html_content = f.read()
|
| 59 |
encoded_html = base64.b64encode(html_content.encode('utf-8')).decode('utf-8')
|
| 60 |
iframe_src = f"data:text/html;base64,{encoded_html}"
|
| 61 |
iframe = f'<iframe src="{iframe_src}" width="100%" height="600px"></iframe>'
|
| 62 |
download_link = f'<a href="data:text/html;base64,{encoded_html}" download="result_{unique_id}.html">Download Full Result</a>'
|
| 63 |
-
return
|
| 64 |
else:
|
| 65 |
-
return
|
| 66 |
except Exception as e:
|
| 67 |
return f"Error: {str(e)}", None
|
| 68 |
finally:
|
|
@@ -154,7 +156,7 @@ with gr.Blocks() as demo:
|
|
| 154 |
submit_button = gr.Button("Submit")
|
| 155 |
|
| 156 |
with gr.Column():
|
| 157 |
-
ocr_result = gr.
|
| 158 |
|
| 159 |
with gr.Column():
|
| 160 |
html_result = gr.HTML(label="rendered html", show_label=True)
|
|
|
|
| 53 |
elif got_mode == "format fine-grained OCR":
|
| 54 |
res = model.chat(tokenizer, image_path, ocr_type='format', ocr_box=ocr_box, ocr_color=ocr_color, render=True, save_render_file=result_path)
|
| 55 |
|
| 56 |
+
res_markdown = f"$$ {res} $$"
|
| 57 |
+
|
| 58 |
+
if "format" in got_mode and os.path.exists(result_path):
|
| 59 |
with open(result_path, 'r') as f:
|
| 60 |
html_content = f.read()
|
| 61 |
encoded_html = base64.b64encode(html_content.encode('utf-8')).decode('utf-8')
|
| 62 |
iframe_src = f"data:text/html;base64,{encoded_html}"
|
| 63 |
iframe = f'<iframe src="{iframe_src}" width="100%" height="600px"></iframe>'
|
| 64 |
download_link = f'<a href="data:text/html;base64,{encoded_html}" download="result_{unique_id}.html">Download Full Result</a>'
|
| 65 |
+
return res_markdown, f"{download_link}<br>{iframe}"
|
| 66 |
else:
|
| 67 |
+
return res_markdown, None
|
| 68 |
except Exception as e:
|
| 69 |
return f"Error: {str(e)}", None
|
| 70 |
finally:
|
|
|
|
| 156 |
submit_button = gr.Button("Submit")
|
| 157 |
|
| 158 |
with gr.Column():
|
| 159 |
+
ocr_result = gr.Markdown(label="GOT output")
|
| 160 |
|
| 161 |
with gr.Column():
|
| 162 |
html_result = gr.HTML(label="rendered html", show_label=True)
|