Spaces:
Sleeping
Sleeping
| import fitz # PyMuPDF | |
| import gradio as gr | |
| def extract_text_from_pdf(file): | |
| if file is None: | |
| return "No file uploaded." | |
| try: | |
| doc = fitz.open(file.name) # Use file path directly | |
| full_text = "" | |
| for page_num in range(len(doc)): | |
| page = doc.load_page(page_num) | |
| text = page.get_text() | |
| full_text += f"\n\n--- Page {page_num + 1} ---\n\n{text}" | |
| return full_text | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| gr.Interface( | |
| fn=extract_text_from_pdf, | |
| inputs=gr.File(label="Upload PDF", file_types=[".pdf"]), | |
| outputs="text", | |
| title="PDF to Text Extractor", | |
| description="Upload a PDF file and get all the extracted text from each page.", | |
| ).launch() | |