|
|
import gradio as gr |
|
|
import os |
|
|
from src.processing.gemini_processor import GeminiProcessor |
|
|
from src.analysis.coverage_generator import CoverageGenerator |
|
|
from pathlib import Path |
|
|
|
|
|
def process_pdf(pdf_file, progress=gr.Progress()): |
|
|
if pdf_file is None: |
|
|
raise gr.Error("Please upload a PDF file") |
|
|
|
|
|
progress(0.1, desc="Initializing...") |
|
|
processor = GeminiProcessor() |
|
|
coverage_gen = CoverageGenerator() |
|
|
|
|
|
try: |
|
|
|
|
|
progress(0.4, desc="Processing screenplay...") |
|
|
cleaned_path = Path("cleaned_screenplay_long.txt") |
|
|
success = processor.process_screenplay(pdf_file.name, str(cleaned_path)) |
|
|
if not success: |
|
|
raise gr.Error("Failed to process screenplay") |
|
|
|
|
|
|
|
|
progress(0.8, desc="Generating coverage...") |
|
|
success = coverage_gen.generate_coverage(cleaned_path) |
|
|
if not success: |
|
|
raise gr.Error("Failed to generate coverage") |
|
|
|
|
|
|
|
|
with open(cleaned_path, 'r') as f: |
|
|
cleaned_text = f.read() |
|
|
with open(Path("coverage.txt"), 'r') as f: |
|
|
coverage = f.read() |
|
|
|
|
|
progress(1.0, desc="Complete!") |
|
|
return cleaned_text, coverage |
|
|
|
|
|
except Exception as e: |
|
|
raise gr.Error(f"Error: {str(e)}") |
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=process_pdf, |
|
|
inputs=gr.File(label="Upload Screenplay PDF", file_types=[".pdf"]), |
|
|
outputs=[ |
|
|
gr.Textbox(label="Cleaned Screenplay", lines=10), |
|
|
gr.Textbox(label="Coverage Document", lines=10) |
|
|
], |
|
|
title="Screenplay Coverage Generator", |
|
|
description="Upload a screenplay PDF to generate coverage analysis" |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |