yalrashed commited on
Commit
ccb1a82
·
verified ·
1 Parent(s): fa7b0ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -9
app.py CHANGED
@@ -53,8 +53,10 @@ def process_screenplay(pdf_file, progress=gr.Progress()):
53
 
54
  progress(1.0, desc="Complete!")
55
  return [cleaned_text, gr.update(interactive=True, variant="primary"),
56
- gr.update(interactive=True, variant="primary"), console.get_output()]
57
-
 
 
58
  except Exception as e:
59
  error_msg = f"Error: {str(e)}"
60
  console.write(error_msg)
@@ -89,18 +91,32 @@ def analyze_screenplay(progress=gr.Progress()):
89
  logger = setup_logging(console)
90
 
91
  try:
92
- # Step 1: Creative Analysis
93
  analyzer = CreativeAnalyzer()
94
- progress(0.3, desc="Performing creative analysis...")
95
  cleaned_path = Path("cleaned_screenplay_long.txt")
96
  success = analyzer.analyze_screenplay(cleaned_path)
97
 
98
  if not success:
99
  raise gr.Error("Failed to generate creative analysis")
100
 
101
- # Step 2: Post Processing
102
- progress(0.6, desc="Post-processing analysis...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  post_processor = AnalysisPostProcessor()
 
104
  input_path = Path("creative_analysis.txt")
105
  output_path = Path("cleaned_creative_analysis.txt")
106
  success = post_processor.process_analysis(str(input_path), str(output_path))
@@ -114,7 +130,6 @@ def analyze_screenplay(progress=gr.Progress()):
114
  progress(1.0, desc="Complete!")
115
  return [analysis, console.get_output()]
116
 
117
-
118
  except Exception as e:
119
  error_msg = f"Error: {str(e)}"
120
  console.write(error_msg)
@@ -130,6 +145,7 @@ with gr.Blocks(title="Screenplay Coverage Generator") as demo:
130
  process_btn = gr.Button("Process Screenplay", variant="primary")
131
  coverage_btn = gr.Button("Generate Coverage", interactive=False)
132
  analysis_btn = gr.Button("Creative Analysis", interactive=False)
 
133
 
134
  with gr.Row():
135
  console = gr.Textbox(label="Console Output", lines=10, max_lines=30, autoscroll=True, show_copy_button=True)
@@ -141,11 +157,13 @@ with gr.Blocks(title="Screenplay Coverage Generator") as demo:
141
  coverage_output = gr.Textbox(label="Coverage Document", lines=10, show_copy_button=True)
142
  with gr.TabItem("Creative Analysis"):
143
  analysis_output = gr.Textbox(label="Creative Analysis", lines=10, show_copy_button=True)
 
 
144
 
145
  process_btn.click(
146
  fn=process_screenplay,
147
  inputs=[file_input],
148
- outputs=[cleaned_output, coverage_btn, analysis_btn, console]
149
  )
150
 
151
  coverage_btn.click(
@@ -155,7 +173,12 @@ with gr.Blocks(title="Screenplay Coverage Generator") as demo:
155
 
156
  analysis_btn.click(
157
  fn=analyze_screenplay,
158
- outputs=[analysis_output, console]
 
 
 
 
 
159
  )
160
 
161
  if __name__ == "__main__":
 
53
 
54
  progress(1.0, desc="Complete!")
55
  return [cleaned_text, gr.update(interactive=True, variant="primary"),
56
+ gr.update(interactive=True, variant="primary"),
57
+ gr.update(interactive=False, variant="secondary"),
58
+ console.get_output()]
59
+
60
  except Exception as e:
61
  error_msg = f"Error: {str(e)}"
62
  console.write(error_msg)
 
91
  logger = setup_logging(console)
92
 
93
  try:
 
94
  analyzer = CreativeAnalyzer()
95
+ progress(0.5, desc="Performing creative analysis...")
96
  cleaned_path = Path("cleaned_screenplay_long.txt")
97
  success = analyzer.analyze_screenplay(cleaned_path)
98
 
99
  if not success:
100
  raise gr.Error("Failed to generate creative analysis")
101
 
102
+ with open(Path("creative_analysis.txt"), 'r') as f:
103
+ analysis = f.read()
104
+
105
+ progress(1.0, desc="Complete!")
106
+ return [analysis, gr.update(interactive=True, variant="primary"), console.get_output()]
107
+
108
+ except Exception as e:
109
+ error_msg = f"Error: {str(e)}"
110
+ console.write(error_msg)
111
+ raise gr.Error(error_msg)
112
+
113
+ def post_process_analysis(progress=gr.Progress()):
114
+ console = ConsoleOutput()
115
+ logger = setup_logging(console)
116
+
117
+ try:
118
  post_processor = AnalysisPostProcessor()
119
+ progress(0.5, desc="Post-processing analysis...")
120
  input_path = Path("creative_analysis.txt")
121
  output_path = Path("cleaned_creative_analysis.txt")
122
  success = post_processor.process_analysis(str(input_path), str(output_path))
 
130
  progress(1.0, desc="Complete!")
131
  return [analysis, console.get_output()]
132
 
 
133
  except Exception as e:
134
  error_msg = f"Error: {str(e)}"
135
  console.write(error_msg)
 
145
  process_btn = gr.Button("Process Screenplay", variant="primary")
146
  coverage_btn = gr.Button("Generate Coverage", interactive=False)
147
  analysis_btn = gr.Button("Creative Analysis", interactive=False)
148
+ post_process_btn = gr.Button("Post-Process Analysis", interactive=False)
149
 
150
  with gr.Row():
151
  console = gr.Textbox(label="Console Output", lines=10, max_lines=30, autoscroll=True, show_copy_button=True)
 
157
  coverage_output = gr.Textbox(label="Coverage Document", lines=10, show_copy_button=True)
158
  with gr.TabItem("Creative Analysis"):
159
  analysis_output = gr.Textbox(label="Creative Analysis", lines=10, show_copy_button=True)
160
+ with gr.TabItem("Post-Processed Analysis"):
161
+ post_process_output = gr.Textbox(label="Post-Processed Analysis", lines=10, show_copy_button=True)
162
 
163
  process_btn.click(
164
  fn=process_screenplay,
165
  inputs=[file_input],
166
+ outputs=[cleaned_output, coverage_btn, analysis_btn, post_process_btn, console]
167
  )
168
 
169
  coverage_btn.click(
 
173
 
174
  analysis_btn.click(
175
  fn=analyze_screenplay,
176
+ outputs=[analysis_output, post_process_btn, console]
177
+ )
178
+
179
+ post_process_btn.click(
180
+ fn=post_process_analysis,
181
+ outputs=[post_process_output, console]
182
  )
183
 
184
  if __name__ == "__main__":