File size: 831 Bytes
ab366bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()