Spaces:
Runtime error
Runtime error
Commit
•
a4d4413
1
Parent(s):
27b3178
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,48 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import pdf2image
|
3 |
-
import numpy as np
|
4 |
-
|
5 |
-
# Convert a PDF to images
|
6 |
-
def pdf_to_imgs(pdf):
|
7 |
-
"""
|
8 |
-
pdf: pdf file
|
9 |
-
first_page: convert to image only the first page
|
10 |
-
return numpy array of the first page and number of images
|
11 |
-
"""
|
12 |
-
|
13 |
-
# get path to pdf
|
14 |
-
path_to_pdf = pdf.name
|
15 |
-
|
16 |
-
# convert PDF to PIL images (one image by page)
|
17 |
-
first_page=True # we want here only the first page as image
|
18 |
-
if first_page: last_page = 1
|
19 |
-
else: last_page = None
|
20 |
-
|
21 |
-
imgs = pdf2image.convert_from_path(path_to_pdf, last_page=last_page)
|
22 |
-
#num_pages = len(imgs)
|
23 |
-
|
24 |
-
#return np.array(imgs[0]), num_pages
|
25 |
-
return np.array(imgs[0])
|
26 |
-
|
27 |
-
title = "PDF to images"
|
28 |
-
description = "Drop a PDF (WARNING: only the first page will be converted into an image)."
|
29 |
-
examples =[["exemple.pdf"]]
|
30 |
-
css = ".output-image, .input-image, .image-preview {height: 600px !important}"
|
31 |
-
allow_flagging = "never"
|
32 |
-
theme = "peach" # default, huggingface, grass, peach
|
33 |
-
|
34 |
-
iface = gr.Interface(fn=pdf_to_imgs,
|
35 |
-
#inputs=[gr.File(label="PDF"), gr.Checkbox(label="Only first page?", value=True)],
|
36 |
-
inputs=gr.File(label="PDF"),
|
37 |
-
|
38 |
-
outputs=gr.Image(type="numpy", label="image of
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
47 |
iface.launch(debug=False, enable_queue=True)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pdf2image
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
# Convert a PDF to images
|
6 |
+
def pdf_to_imgs(pdf):
|
7 |
+
"""
|
8 |
+
pdf: pdf file
|
9 |
+
first_page: convert to image only the first page
|
10 |
+
return numpy array of the first page and number of images
|
11 |
+
"""
|
12 |
+
|
13 |
+
# get path to pdf
|
14 |
+
path_to_pdf = pdf.name
|
15 |
+
|
16 |
+
# convert PDF to PIL images (one image by page)
|
17 |
+
first_page=True # we want here only the first page as image
|
18 |
+
if first_page: last_page = 1
|
19 |
+
else: last_page = None
|
20 |
+
|
21 |
+
imgs = pdf2image.convert_from_path(path_to_pdf, last_page=last_page)
|
22 |
+
#num_pages = len(imgs)
|
23 |
+
|
24 |
+
#return np.array(imgs[0]), num_pages
|
25 |
+
return np.array(imgs[0])
|
26 |
+
|
27 |
+
title = "PDF to images"
|
28 |
+
description = "Drop a PDF (WARNING: only the first page will be converted into an image)."
|
29 |
+
examples =[["exemple.pdf"]]
|
30 |
+
css = ".output-image, .input-image, .image-preview {height: 600px !important}"
|
31 |
+
allow_flagging = "never"
|
32 |
+
theme = "peach" # default, huggingface, grass, peach
|
33 |
+
|
34 |
+
iface = gr.Interface(fn=pdf_to_imgs,
|
35 |
+
#inputs=[gr.File(label="PDF"), gr.Checkbox(label="Only first page?", value=True)],
|
36 |
+
#inputs=gr.File(label="PDF"),
|
37 |
+
inputs=gr.File(type="filepath", label="PDF"),
|
38 |
+
#outputs=[gr.Image(type="numpy", label="page image"), gr.Textbox(label="number of pages")],
|
39 |
+
outputs=gr.Image(type="numpy", label="image of the first page"),
|
40 |
+
title=title,
|
41 |
+
description=description,
|
42 |
+
examples=examples,
|
43 |
+
#article=article,
|
44 |
+
css=css,
|
45 |
+
allow_flagging=allow_flagging,
|
46 |
+
theme=theme
|
47 |
+
)
|
48 |
iface.launch(debug=False, enable_queue=True)
|