Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from script import process_pdf # Assuming the above script is saved as script.py
|
3 |
+
from pathlib import Path
|
4 |
+
|
5 |
+
OUTPUT_DIR = Path("outputs")
|
6 |
+
OUTPUT_DIR.mkdir(exist_ok=True)
|
7 |
+
|
8 |
+
def process_uploaded_pdf(pdf_file):
|
9 |
+
if pdf_file is None:
|
10 |
+
return "Please upload a PDF file."
|
11 |
+
|
12 |
+
output_txt = OUTPUT_DIR / "analysis_results.txt"
|
13 |
+
process_pdf(pdf_file.name, output_txt)
|
14 |
+
|
15 |
+
# Read and return the results
|
16 |
+
with open(output_txt, 'r', encoding='utf-8') as f:
|
17 |
+
results = f.read()
|
18 |
+
|
19 |
+
return results
|
20 |
+
|
21 |
+
# Create Gradio interface
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=process_uploaded_pdf,
|
24 |
+
inputs=gr.File(label="Upload PDF"),
|
25 |
+
outputs=gr.Textbox(label="Analysis Results"),
|
26 |
+
title="PDF Analyzer",
|
27 |
+
description="Upload a PDF file to extract text and analyze images."
|
28 |
+
)
|
29 |
+
|
30 |
+
interface.launch()
|