Team Ai
Apppublic

Rivalcoder/Pdf-Processing

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py26 linesDownload Raw Back to root
1import fitz  # PyMuPDF2import gradio as gr3 4def extract_text_from_pdf(file):5    if file is None:6        return "No file uploaded."7    8    try:9        doc = fitz.open(file.name)  # Use file path directly10        full_text = ""11        for page_num in range(len(doc)):12            page = doc.load_page(page_num)13            text = page.get_text()14            full_text += f"\n\n--- Page {page_num + 1} ---\n\n{text}"15        return full_text16    except Exception as e:17        return f"Error: {str(e)}"18 19gr.Interface(20    fn=extract_text_from_pdf,21    inputs=gr.File(label="Upload PDF", file_types=[".pdf"]),22    outputs="text",23    title="PDF to Text Extractor",24    description="Upload a PDF file and get all the extracted text from each page.",25).launch()26