|
import gradio as gr |
|
from script import process_pdf |
|
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) |
|
|
|
|
|
with open(output_txt, 'r', encoding='utf-8') as f: |
|
results = f.read() |
|
|
|
return results |
|
|
|
|
|
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() |