ocr-pdf / app.py
Deadmon's picture
Create app.py
ab366bd verified
raw
history blame
831 Bytes
import gradio as gr
from script import process_pdf # Assuming the above script is saved as script.py
from pathlib import Path
OUTPUT_DIR = Path("outputs")
OUTPUT_DIR.mkdir(exist_ok=True)
def process_uploaded_pdf(pdf_file):
if pdf_file is None:
return "Please upload a PDF file."
output_txt = OUTPUT_DIR / "analysis_results.txt"
process_pdf(pdf_file.name, output_txt)
# Read and return the results
with open(output_txt, 'r', encoding='utf-8') as f:
results = f.read()
return results
# Create Gradio interface
interface = gr.Interface(
fn=process_uploaded_pdf,
inputs=gr.File(label="Upload PDF"),
outputs=gr.Textbox(label="Analysis Results"),
title="PDF Analyzer",
description="Upload a PDF file to extract text and analyze images."
)
interface.launch()