Spaces:
Runtime error
Runtime error
Download app.py from giacomov/pdffigures2: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/giacomov/pdffigures2/resolve/689a76fc05b2a831b5a9abb97aa0fd14c349b96f/app.py
- Command line
-
hf download hf://spaces/giacomov/pdffigures2@689a76fc05b2a831b5a9abb97aa0fd14c349b96f/app.py
-
curl -L -o app.py https://huggingface.co/spaces/giacomov/pdffigures2/resolve/689a76fc05b2a831b5a9abb97aa0fd14c349b96f/app.py
1.21 kB
| import gradio as gr | |
| import urllib.request | |
| import subprocess | |
| import os | |
| import glob | |
| def extract_figure(url): | |
| # download PDF file from URL | |
| urllib.request.urlretrieve(url, "input.pdf") | |
| # extract first figure from PDF using pdffigures2 | |
| subprocess.run(["java", "-jar", "pdffigures2.jar", "input.pdf", "-m", "figures_"]) | |
| all_pngs = glob.glob("*.png") | |
| print(all_pngs) | |
| # get path to first figure | |
| figure_path = "figures_input-Figure1-1.png" | |
| # # read first figure from file | |
| # with open(figure_path, "rb") as f: | |
| # figure_bytes = f.read() | |
| # # delete downloaded file and figure file | |
| # os.remove("input.pdf") | |
| # os.remove(figure_path) | |
| # return first figure | |
| return figure_path | |
| # define input and output interfaces | |
| inputs = gr.inputs.Textbox(label="Enter URL of PDF file:") | |
| outputs = gr.outputs.Image(label="First figure in PDF:", type="filepath") | |
| # create interface | |
| interface = gr.Interface(fn=extract_figure, inputs=inputs, outputs=outputs, title="Extract First Figure from PDF", description="Enter the URL of a PDF file and the first figure in the file will be extracted and displayed.") | |
| # launch interface | |
| interface.launch() | |