Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -289,7 +289,6 @@ class MaestroEngine:
|
|
| 289 |
|
| 290 |
return f"Recalled {len(fetched_data)} entries from memory:\n\n{json.dumps(fetched_data, indent=2)}"
|
| 291 |
|
| 292 |
-
|
| 293 |
# --- GRADIO APPLICATION ---
|
| 294 |
class GradioApp:
|
| 295 |
def __init__(self, engine: MaestroEngine):
|
|
@@ -330,42 +329,69 @@ class GradioApp:
|
|
| 330 |
recall_button = gr.Button("Recall", variant="primary")
|
| 331 |
memory_output = gr.Textbox(label="Recalled Information", lines=20, interactive=False)
|
| 332 |
|
| 333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
recall_button.click(self.engine.recall_from_memory, [memory_query], [memory_output])
|
| 335 |
return app
|
| 336 |
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
ingested_text, errors = self.engine.process_data_sources(text, files, url, pdf_url, pdf_batch)
|
| 341 |
if errors:
|
| 342 |
log(f"Ingestion errors: {errors}")
|
| 343 |
-
|
| 344 |
-
|
| 345 |
if not ingested_text:
|
| 346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
|
| 348 |
-
# 2. Save to Memory (if requested)
|
| 349 |
if do_mem:
|
| 350 |
self.engine.save_to_memory(ingested_text, task)
|
| 351 |
-
# We don't wait for this to finish for the UI, it's a background-like task
|
| 352 |
|
| 353 |
-
|
| 354 |
if do_sum or do_rep:
|
| 355 |
-
|
| 356 |
-
return report, summaries
|
| 357 |
|
| 358 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
def launch(self): self.app.launch(debug=Config.VERBOSE, share=False)
|
| 361 |
|
| 362 |
-
if __name__ == "__main__":
|
| 363 |
if not Config.HF_TOKEN:
|
|
|
|
| 364 |
print("FATAL: HF_TOKEN environment variable not set.")
|
| 365 |
else:
|
| 366 |
-
log("Instantiating Maestro Engine...")
|
| 367 |
-
engine = MaestroEngine()
|
| 368 |
-
app = GradioApp(engine)
|
| 369 |
log("Launching Gradio App...")
|
| 370 |
-
app.launch()
|
| 371 |
-
|
|
|
|
| 289 |
|
| 290 |
return f"Recalled {len(fetched_data)} entries from memory:\n\n{json.dumps(fetched_data, indent=2)}"
|
| 291 |
|
|
|
|
| 292 |
# --- GRADIO APPLICATION ---
|
| 293 |
class GradioApp:
|
| 294 |
def __init__(self, engine: MaestroEngine):
|
|
|
|
| 329 |
recall_button = gr.Button("Recall", variant="primary")
|
| 330 |
memory_output = gr.Textbox(label="Recalled Information", lines=20, interactive=False)
|
| 331 |
|
| 332 |
+
# --- CORRECTION PART 1: The event listener now expects 4 outputs ---
|
| 333 |
+
# The output components match the error: [state, textbox, textbox, button]
|
| 334 |
+
# In our code, these are: session_id, final_report_output, json_summary_output, process_button
|
| 335 |
+
process_button.click(
|
| 336 |
+
self._synthesis_workflow,
|
| 337 |
+
[session_id, task_instructions, text_input, file_upload, url_input, pdf_url_input, pdf_batch_input, summarize_check, report_check, memory_check],
|
| 338 |
+
[session_id, final_report_output, json_summary_output, process_button]
|
| 339 |
+
)
|
| 340 |
recall_button.click(self.engine.recall_from_memory, [memory_query], [memory_output])
|
| 341 |
return app
|
| 342 |
|
| 343 |
+
# --- CORRECTION PART 2: The handler function is now a generator that yields updates ---
|
| 344 |
+
def _synthesis_workflow(self, session, task, text, files, url, pdf_url, pdf_batch, do_sum, do_rep, do_mem):
|
| 345 |
+
log(f"Starting synthesis workflow for session: {session}")
|
| 346 |
+
|
| 347 |
+
# 1. First yield: Immediately update the UI to show a "processing" state.
|
| 348 |
+
# This provides a value for all 4 output components.
|
| 349 |
+
yield {
|
| 350 |
+
session_id: session, # The state component doesn't need to be changed
|
| 351 |
+
final_report_output: "⚙️ Processing... Please wait.",
|
| 352 |
+
json_summary_output: None,
|
| 353 |
+
process_button: gr.update(value="Processing...", interactive=False)
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
# 2. Perform the actual work
|
| 357 |
ingested_text, errors = self.engine.process_data_sources(text, files, url, pdf_url, pdf_batch)
|
| 358 |
if errors:
|
| 359 |
log(f"Ingestion errors: {errors}")
|
| 360 |
+
|
|
|
|
| 361 |
if not ingested_text:
|
| 362 |
+
# Final yield (or return) in case of error
|
| 363 |
+
yield {
|
| 364 |
+
session_id: session,
|
| 365 |
+
final_report_output: "## Error\nNo data was successfully ingested. Please check your inputs.",
|
| 366 |
+
json_summary_output: {"errors": errors},
|
| 367 |
+
process_button: gr.update(value="🚀 Process & Synthesize", interactive=True)
|
| 368 |
+
}
|
| 369 |
+
return # Stop execution here
|
| 370 |
|
|
|
|
| 371 |
if do_mem:
|
| 372 |
self.engine.save_to_memory(ingested_text, task)
|
|
|
|
| 373 |
|
| 374 |
+
report_result, summaries_result = "Processing was not requested.", None
|
| 375 |
if do_sum or do_rep:
|
| 376 |
+
report_result, summaries_result = self.engine.synthesis_workflow(ingested_text, task, do_sum, do_rep)
|
|
|
|
| 377 |
|
| 378 |
+
# 3. Final yield: Return the final results and re-enable the button.
|
| 379 |
+
# This also provides a value for all 4 output components.
|
| 380 |
+
yield {
|
| 381 |
+
session_id: session,
|
| 382 |
+
final_report_output: report_result,
|
| 383 |
+
json_summary_output: summaries_result,
|
| 384 |
+
process_button: gr.update(value="🚀 Process & Synthesize", interactive=True)
|
| 385 |
+
}
|
| 386 |
|
| 387 |
def launch(self): self.app.launch(debug=Config.VERBOSE, share=False)
|
| 388 |
|
| 389 |
+
if __name__ == "__main__ ":
|
| 390 |
if not Config.HF_TOKEN:
|
| 391 |
+
|
| 392 |
print("FATAL: HF_TOKEN environment variable not set.")
|
| 393 |
else:
|
| 394 |
+
log("Instantiating Maestro Engine...")
|
| 395 |
+
engine = MaestroEngine() app = GradioApp(engine)
|
|
|
|
| 396 |
log("Launching Gradio App...")
|
| 397 |
+
app.launch()
|
|
|