Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,9 @@ os.system('cp magic-pdf.template.json ~/magic-pdf.json')
|
|
19 |
os.system(f"sed -i 's|/tmp/models|{model_dir}/models|g' /home/user/magic-pdf.json")
|
20 |
# os.system("sed -i 's|cpu|cuda|g' /home/user/magic-pdf.json")
|
21 |
|
|
|
|
|
|
|
22 |
import gradio as gr
|
23 |
from loguru import logger
|
24 |
|
@@ -119,12 +122,16 @@ def to_markdown(file_path, end_pages):
|
|
119 |
return md_content, txt_content, archive_zip_path, show_pdf(new_pdf_path)
|
120 |
|
121 |
|
122 |
-
def show_pdf(file_path):
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
128 |
|
129 |
|
130 |
latex_delimiters = [{"left": "$$", "right": "$$", "display": True},
|
@@ -140,7 +147,8 @@ if __name__ == "__main__":
|
|
140 |
change_bu = gr.Button("Convert")
|
141 |
clear_bu = gr.ClearButton([file, max_pages], value="Clear")
|
142 |
gr.Markdown(value="### PDF preview")
|
143 |
-
pdf_show = gr.HTML(label="PDF preview")
|
|
|
144 |
|
145 |
with gr.Column(variant='panel', scale=5):
|
146 |
output_file = gr.File(label="convert result", interactive=False)
|
|
|
19 |
os.system(f"sed -i 's|/tmp/models|{model_dir}/models|g' /home/user/magic-pdf.json")
|
20 |
# os.system("sed -i 's|cpu|cuda|g' /home/user/magic-pdf.json")
|
21 |
|
22 |
+
os.system("pip install gradio-pdf")
|
23 |
+
from gradio_pdf import PDF
|
24 |
+
|
25 |
import gradio as gr
|
26 |
from loguru import logger
|
27 |
|
|
|
122 |
return md_content, txt_content, archive_zip_path, show_pdf(new_pdf_path)
|
123 |
|
124 |
|
125 |
+
# def show_pdf(file_path):
|
126 |
+
# with open(file_path, "rb") as f:
|
127 |
+
# base64_pdf = base64.b64encode(f.read()).decode('utf-8')
|
128 |
+
# pdf_display = f'<embed src="data:application/pdf;base64,{base64_pdf}" ' \
|
129 |
+
# f'width="100%" height="1000" type="application/pdf">'
|
130 |
+
# return pdf_display
|
131 |
+
|
132 |
+
|
133 |
+
def show_pdf(file):
|
134 |
+
return file
|
135 |
|
136 |
|
137 |
latex_delimiters = [{"left": "$$", "right": "$$", "display": True},
|
|
|
147 |
change_bu = gr.Button("Convert")
|
148 |
clear_bu = gr.ClearButton([file, max_pages], value="Clear")
|
149 |
gr.Markdown(value="### PDF preview")
|
150 |
+
# pdf_show = gr.HTML(label="PDF preview")
|
151 |
+
pdf_show = PDF(label="PDF preview", interactive=True, height=1000)
|
152 |
|
153 |
with gr.Column(variant='panel', scale=5):
|
154 |
output_file = gr.File(label="convert result", interactive=False)
|