Spaces:
Sleeping
Sleeping
Download app.py from imranalishah/pdf_Reader: direct link, hf CLI and curl.
- Browser
- Download file 808 Bytes
-
https://huggingface.co/spaces/imranalishah/pdf_Reader/resolve/main/app.py
- Command line
-
hf download hf://spaces/imranalishah/pdf_Reader/app.py
-
curl -L -o app.py https://huggingface.co/spaces/imranalishah/pdf_Reader/resolve/main/app.py
808 Bytes
| import gradio as gr | |
| import pdfplumber | |
| from docx import Document | |
| import os | |
| def pdf_to_docx(file): | |
| if not file: | |
| return "No file uploaded" | |
| # Extract text from PDF | |
| with pdfplumber.open(file.name) as pdf: | |
| full_text = "" | |
| for page in pdf.pages: | |
| full_text += page.extract_text() + "\n" | |
| # Create Word Document | |
| doc = Document() | |
| doc.add_paragraph(full_text) | |
| output_path = "output.docx" | |
| doc.save(output_path) | |
| return output_path | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=pdf_to_docx, | |
| inputs=gr.File(label="Upload PDF"), | |
| outputs=gr.File(label="Download Word Document"), | |
| title="PDF to Word Converter", | |
| description="Upload a PDF and download the content as a Word document." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |