Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ 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 |
import logging
|
| 7 |
|
|
@@ -24,12 +25,6 @@ def process_screenplay(pdf_file, progress=gr.Progress()):
|
|
| 24 |
logging.basicConfig(level=logging.DEBUG)
|
| 25 |
logger = logging.getLogger()
|
| 26 |
logger.handlers = []
|
| 27 |
-
|
| 28 |
-
class GradioHandler(logging.Handler):
|
| 29 |
-
def emit(self, record):
|
| 30 |
-
msg = self.format(record)
|
| 31 |
-
console.write(msg)
|
| 32 |
-
|
| 33 |
logger.addHandler(GradioHandler())
|
| 34 |
|
| 35 |
try:
|
|
@@ -40,12 +35,13 @@ def process_screenplay(pdf_file, progress=gr.Progress()):
|
|
| 40 |
|
| 41 |
if not success:
|
| 42 |
raise gr.Error("Failed to process screenplay")
|
| 43 |
-
|
| 44 |
with open(cleaned_path, 'r') as f:
|
| 45 |
cleaned_text = f.read()
|
| 46 |
|
| 47 |
progress(1.0, desc="Complete!")
|
| 48 |
-
return [cleaned_text, gr.update(interactive=True, variant="primary"),
|
|
|
|
| 49 |
|
| 50 |
except Exception as e:
|
| 51 |
error_msg = f"Error: {str(e)}"
|
|
@@ -57,12 +53,6 @@ def generate_coverage(progress=gr.Progress()):
|
|
| 57 |
logging.basicConfig(level=logging.DEBUG)
|
| 58 |
logger = logging.getLogger()
|
| 59 |
logger.handlers = []
|
| 60 |
-
|
| 61 |
-
class GradioHandler(logging.Handler):
|
| 62 |
-
def emit(self, record):
|
| 63 |
-
msg = self.format(record)
|
| 64 |
-
console.write(msg)
|
| 65 |
-
|
| 66 |
logger.addHandler(GradioHandler())
|
| 67 |
|
| 68 |
try:
|
|
@@ -85,6 +75,33 @@ def generate_coverage(progress=gr.Progress()):
|
|
| 85 |
console.write(error_msg)
|
| 86 |
raise gr.Error(error_msg)
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
with gr.Blocks(title="Screenplay Coverage Generator") as demo:
|
| 89 |
gr.Markdown("# Screenplay Coverage Generator")
|
| 90 |
|
|
@@ -94,6 +111,7 @@ with gr.Blocks(title="Screenplay Coverage Generator") as demo:
|
|
| 94 |
with gr.Row():
|
| 95 |
process_btn = gr.Button("Process Screenplay", variant="primary")
|
| 96 |
coverage_btn = gr.Button("Generate Coverage", interactive=False)
|
|
|
|
| 97 |
|
| 98 |
with gr.Row():
|
| 99 |
console = gr.Textbox(label="Console Output", lines=10, max_lines=30, autoscroll=True, show_copy_button=True)
|
|
@@ -103,17 +121,24 @@ with gr.Blocks(title="Screenplay Coverage Generator") as demo:
|
|
| 103 |
cleaned_output = gr.Textbox(label="Cleaned Screenplay", lines=10, show_copy_button=True)
|
| 104 |
with gr.TabItem("Coverage"):
|
| 105 |
coverage_output = gr.Textbox(label="Coverage Document", lines=10, show_copy_button=True)
|
|
|
|
|
|
|
| 106 |
|
| 107 |
process_btn.click(
|
| 108 |
fn=process_screenplay,
|
| 109 |
inputs=[file_input],
|
| 110 |
-
outputs=[cleaned_output, coverage_btn, console]
|
| 111 |
)
|
| 112 |
|
| 113 |
coverage_btn.click(
|
| 114 |
fn=generate_coverage,
|
| 115 |
outputs=[coverage_output, console]
|
| 116 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
if __name__ == "__main__":
|
| 119 |
demo.launch()
|
|
|
|
| 2 |
import os
|
| 3 |
from src.processing.gemini_processor import GeminiProcessor
|
| 4 |
from src.analysis.coverage_generator import CoverageGenerator
|
| 5 |
+
from src.analysis.creative_analyzer import CreativeAnalyzer
|
| 6 |
from pathlib import Path
|
| 7 |
import logging
|
| 8 |
|
|
|
|
| 25 |
logging.basicConfig(level=logging.DEBUG)
|
| 26 |
logger = logging.getLogger()
|
| 27 |
logger.handlers = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
logger.addHandler(GradioHandler())
|
| 29 |
|
| 30 |
try:
|
|
|
|
| 35 |
|
| 36 |
if not success:
|
| 37 |
raise gr.Error("Failed to process screenplay")
|
| 38 |
+
|
| 39 |
with open(cleaned_path, 'r') as f:
|
| 40 |
cleaned_text = f.read()
|
| 41 |
|
| 42 |
progress(1.0, desc="Complete!")
|
| 43 |
+
return [cleaned_text, gr.update(interactive=True, variant="primary"),
|
| 44 |
+
gr.update(interactive=True, variant="primary"), console.get_output()]
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
error_msg = f"Error: {str(e)}"
|
|
|
|
| 53 |
logging.basicConfig(level=logging.DEBUG)
|
| 54 |
logger = logging.getLogger()
|
| 55 |
logger.handlers = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
logger.addHandler(GradioHandler())
|
| 57 |
|
| 58 |
try:
|
|
|
|
| 75 |
console.write(error_msg)
|
| 76 |
raise gr.Error(error_msg)
|
| 77 |
|
| 78 |
+
def analyze_screenplay(progress=gr.Progress()):
|
| 79 |
+
console = ConsoleOutput()
|
| 80 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 81 |
+
logger = logging.getLogger()
|
| 82 |
+
logger.handlers = []
|
| 83 |
+
logger.addHandler(GradioHandler())
|
| 84 |
+
|
| 85 |
+
try:
|
| 86 |
+
analyzer = CreativeAnalyzer()
|
| 87 |
+
progress(0.5, desc="Performing creative analysis...")
|
| 88 |
+
cleaned_path = Path("cleaned_screenplay_long.txt")
|
| 89 |
+
success = analyzer.analyze_screenplay(cleaned_path)
|
| 90 |
+
|
| 91 |
+
if not success:
|
| 92 |
+
raise gr.Error("Failed to generate creative analysis")
|
| 93 |
+
|
| 94 |
+
with open(Path("creative_analysis.txt"), 'r') as f:
|
| 95 |
+
analysis = f.read()
|
| 96 |
+
|
| 97 |
+
progress(1.0, desc="Complete!")
|
| 98 |
+
return [analysis, console.get_output()]
|
| 99 |
+
|
| 100 |
+
except Exception as e:
|
| 101 |
+
error_msg = f"Error: {str(e)}"
|
| 102 |
+
console.write(error_msg)
|
| 103 |
+
raise gr.Error(error_msg)
|
| 104 |
+
|
| 105 |
with gr.Blocks(title="Screenplay Coverage Generator") as demo:
|
| 106 |
gr.Markdown("# Screenplay Coverage Generator")
|
| 107 |
|
|
|
|
| 111 |
with gr.Row():
|
| 112 |
process_btn = gr.Button("Process Screenplay", variant="primary")
|
| 113 |
coverage_btn = gr.Button("Generate Coverage", interactive=False)
|
| 114 |
+
analysis_btn = gr.Button("Creative Analysis", interactive=False)
|
| 115 |
|
| 116 |
with gr.Row():
|
| 117 |
console = gr.Textbox(label="Console Output", lines=10, max_lines=30, autoscroll=True, show_copy_button=True)
|
|
|
|
| 121 |
cleaned_output = gr.Textbox(label="Cleaned Screenplay", lines=10, show_copy_button=True)
|
| 122 |
with gr.TabItem("Coverage"):
|
| 123 |
coverage_output = gr.Textbox(label="Coverage Document", lines=10, show_copy_button=True)
|
| 124 |
+
with gr.TabItem("Creative Analysis"):
|
| 125 |
+
analysis_output = gr.Textbox(label="Creative Analysis", lines=10, show_copy_button=True)
|
| 126 |
|
| 127 |
process_btn.click(
|
| 128 |
fn=process_screenplay,
|
| 129 |
inputs=[file_input],
|
| 130 |
+
outputs=[cleaned_output, coverage_btn, analysis_btn, console]
|
| 131 |
)
|
| 132 |
|
| 133 |
coverage_btn.click(
|
| 134 |
fn=generate_coverage,
|
| 135 |
outputs=[coverage_output, console]
|
| 136 |
)
|
| 137 |
+
|
| 138 |
+
analysis_btn.click(
|
| 139 |
+
fn=analyze_screenplay,
|
| 140 |
+
outputs=[analysis_output, console]
|
| 141 |
+
)
|
| 142 |
|
| 143 |
if __name__ == "__main__":
|
| 144 |
demo.launch()
|