Update app.py
Browse files
app.py
CHANGED
|
@@ -16,19 +16,15 @@ class ConsoleOutput:
|
|
| 16 |
def get_output(self):
|
| 17 |
return "\n".join(self.messages)
|
| 18 |
|
| 19 |
-
def
|
| 20 |
if pdf_file is None:
|
| 21 |
raise gr.Error("Please upload a PDF file")
|
| 22 |
|
| 23 |
console = ConsoleOutput()
|
| 24 |
-
|
| 25 |
-
# Set up logging to console
|
| 26 |
-
logging.basicConfig(level=logging.DEBUG,
|
| 27 |
-
format='%(asctime)s - %(levelname)s - %(message)s')
|
| 28 |
-
|
| 29 |
logger = logging.getLogger()
|
| 30 |
-
logger.handlers = []
|
| 31 |
-
|
| 32 |
class GradioHandler(logging.Handler):
|
| 33 |
def emit(self, record):
|
| 34 |
msg = self.format(record)
|
|
@@ -38,21 +34,43 @@ def process_pdf(pdf_file, progress=gr.Progress()):
|
|
| 38 |
|
| 39 |
try:
|
| 40 |
processor = GeminiProcessor()
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# Clean screenplay
|
| 44 |
-
progress(0.2, desc="Processing screenplay...")
|
| 45 |
cleaned_path = Path("cleaned_screenplay_long.txt")
|
| 46 |
success = processor.process_screenplay(pdf_file.name, str(cleaned_path))
|
|
|
|
| 47 |
if not success:
|
| 48 |
raise gr.Error("Failed to process screenplay")
|
| 49 |
|
| 50 |
with open(cleaned_path, 'r') as f:
|
| 51 |
cleaned_text = f.read()
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
success = coverage_gen.generate_coverage(cleaned_path)
|
|
|
|
| 56 |
if not success:
|
| 57 |
raise gr.Error("Failed to generate coverage")
|
| 58 |
|
|
@@ -60,7 +78,7 @@ def process_pdf(pdf_file, progress=gr.Progress()):
|
|
| 60 |
coverage = f.read()
|
| 61 |
|
| 62 |
progress(1.0, desc="Complete!")
|
| 63 |
-
return
|
| 64 |
|
| 65 |
except Exception as e:
|
| 66 |
error_msg = f"Error: {str(e)}"
|
|
@@ -75,37 +93,26 @@ with gr.Blocks(title="Screenplay Coverage Generator") as demo:
|
|
| 75 |
|
| 76 |
with gr.Row():
|
| 77 |
process_btn = gr.Button("Process Screenplay")
|
|
|
|
| 78 |
|
| 79 |
with gr.Row():
|
| 80 |
-
console = gr.Textbox(
|
| 81 |
-
label="Console Output",
|
| 82 |
-
lines=10,
|
| 83 |
-
max_lines=30,
|
| 84 |
-
autoscroll=True,
|
| 85 |
-
container=True,
|
| 86 |
-
show_copy_button=True
|
| 87 |
-
)
|
| 88 |
|
| 89 |
with gr.Tabs():
|
| 90 |
with gr.TabItem("Cleaned Screenplay"):
|
| 91 |
-
cleaned_output = gr.Textbox(
|
| 92 |
-
label="Cleaned Screenplay",
|
| 93 |
-
lines=10,
|
| 94 |
-
max_lines=30,
|
| 95 |
-
show_copy_button=True
|
| 96 |
-
)
|
| 97 |
with gr.TabItem("Coverage"):
|
| 98 |
-
coverage_output = gr.Textbox(
|
| 99 |
-
label="Coverage Document",
|
| 100 |
-
lines=10,
|
| 101 |
-
max_lines=30,
|
| 102 |
-
show_copy_button=True
|
| 103 |
-
)
|
| 104 |
|
| 105 |
process_btn.click(
|
| 106 |
-
fn=
|
| 107 |
inputs=[file_input],
|
| 108 |
-
outputs=[cleaned_output,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
)
|
| 110 |
|
| 111 |
if __name__ == "__main__":
|
|
|
|
| 16 |
def get_output(self):
|
| 17 |
return "\n".join(self.messages)
|
| 18 |
|
| 19 |
+
def process_screenplay(pdf_file, progress=gr.Progress()):
|
| 20 |
if pdf_file is None:
|
| 21 |
raise gr.Error("Please upload a PDF file")
|
| 22 |
|
| 23 |
console = ConsoleOutput()
|
| 24 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
logger = logging.getLogger()
|
| 26 |
+
logger.handlers = []
|
| 27 |
+
|
| 28 |
class GradioHandler(logging.Handler):
|
| 29 |
def emit(self, record):
|
| 30 |
msg = self.format(record)
|
|
|
|
| 34 |
|
| 35 |
try:
|
| 36 |
processor = GeminiProcessor()
|
| 37 |
+
progress(0.5, desc="Processing screenplay...")
|
|
|
|
|
|
|
|
|
|
| 38 |
cleaned_path = Path("cleaned_screenplay_long.txt")
|
| 39 |
success = processor.process_screenplay(pdf_file.name, str(cleaned_path))
|
| 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.Button.update(interactive=True), console.get_output()
|
| 49 |
+
|
| 50 |
+
except Exception as e:
|
| 51 |
+
error_msg = f"Error: {str(e)}"
|
| 52 |
+
console.write(error_msg)
|
| 53 |
+
raise gr.Error(error_msg)
|
| 54 |
+
|
| 55 |
+
def generate_coverage(progress=gr.Progress()):
|
| 56 |
+
console = ConsoleOutput()
|
| 57 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 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:
|
| 69 |
+
coverage_gen = CoverageGenerator()
|
| 70 |
+
progress(0.5, desc="Generating coverage...")
|
| 71 |
+
cleaned_path = Path("cleaned_screenplay_long.txt")
|
| 72 |
success = coverage_gen.generate_coverage(cleaned_path)
|
| 73 |
+
|
| 74 |
if not success:
|
| 75 |
raise gr.Error("Failed to generate coverage")
|
| 76 |
|
|
|
|
| 78 |
coverage = f.read()
|
| 79 |
|
| 80 |
progress(1.0, desc="Complete!")
|
| 81 |
+
return coverage, console.get_output()
|
| 82 |
|
| 83 |
except Exception as e:
|
| 84 |
error_msg = f"Error: {str(e)}"
|
|
|
|
| 93 |
|
| 94 |
with gr.Row():
|
| 95 |
process_btn = gr.Button("Process Screenplay")
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
with gr.Tabs():
|
| 102 |
with gr.TabItem("Cleaned Screenplay"):
|
| 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__":
|