Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,52 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import google.generativeai as genai
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
def process_pdf(pdf_file):
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
demo = gr.Interface(
|
| 10 |
fn=process_pdf,
|
| 11 |
inputs=gr.File(label="Upload Screenplay PDF", file_types=[".pdf"]),
|
| 12 |
outputs=[
|
| 13 |
-
gr.Textbox(label="Cleaned
|
| 14 |
-
gr.Textbox(label="Coverage")
|
| 15 |
],
|
| 16 |
-
title="Screenplay Coverage Generator"
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
+
from src.processing.gemini_processor import GeminiProcessor
|
| 4 |
+
from src.analysis.coverage_generator import CoverageGenerator
|
| 5 |
+
from pathlib import Path
|
| 6 |
|
| 7 |
+
def process_pdf(pdf_file, progress=gr.Progress()):
|
| 8 |
+
if pdf_file is None:
|
| 9 |
+
raise gr.Error("Please upload a PDF file")
|
| 10 |
+
|
| 11 |
+
progress(0.1, desc="Initializing...")
|
| 12 |
+
processor = GeminiProcessor()
|
| 13 |
+
coverage_gen = CoverageGenerator()
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
# Clean screenplay
|
| 17 |
+
progress(0.4, desc="Processing screenplay...")
|
| 18 |
+
cleaned_path = Path("cleaned_screenplay_long.txt")
|
| 19 |
+
success = processor.process_screenplay(pdf_file.name, str(cleaned_path))
|
| 20 |
+
if not success:
|
| 21 |
+
raise gr.Error("Failed to process screenplay")
|
| 22 |
+
|
| 23 |
+
# Generate coverage
|
| 24 |
+
progress(0.8, desc="Generating coverage...")
|
| 25 |
+
success = coverage_gen.generate_coverage(cleaned_path)
|
| 26 |
+
if not success:
|
| 27 |
+
raise gr.Error("Failed to generate coverage")
|
| 28 |
+
|
| 29 |
+
# Read results
|
| 30 |
+
with open(cleaned_path, 'r') as f:
|
| 31 |
+
cleaned_text = f.read()
|
| 32 |
+
with open(Path("coverage.txt"), 'r') as f:
|
| 33 |
+
coverage = f.read()
|
| 34 |
+
|
| 35 |
+
progress(1.0, desc="Complete!")
|
| 36 |
+
return cleaned_text, coverage
|
| 37 |
+
|
| 38 |
+
except Exception as e:
|
| 39 |
+
raise gr.Error(f"Error: {str(e)}")
|
| 40 |
|
| 41 |
demo = gr.Interface(
|
| 42 |
fn=process_pdf,
|
| 43 |
inputs=gr.File(label="Upload Screenplay PDF", file_types=[".pdf"]),
|
| 44 |
outputs=[
|
| 45 |
+
gr.Textbox(label="Cleaned Screenplay", lines=10),
|
| 46 |
+
gr.Textbox(label="Coverage Document", lines=10)
|
| 47 |
],
|
| 48 |
+
title="Screenplay Coverage Generator",
|
| 49 |
+
description="Upload a screenplay PDF to generate coverage analysis"
|
| 50 |
)
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|