Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -528,71 +528,94 @@ if st.button("Generate Patent Insights"):
|
|
528 |
# Start the timer
|
529 |
start_time = time.time()
|
530 |
|
531 |
-
#
|
532 |
if not patent_area or not stakeholder:
|
533 |
st.error("Please provide both Patent Technology Area and Stakeholder.")
|
534 |
-
|
535 |
-
|
536 |
-
|
|
|
|
|
537 |
|
538 |
# Calculate elapsed time
|
539 |
elapsed_time = time.time() - start_time
|
540 |
|
541 |
-
# Extract
|
|
|
|
|
542 |
writer_output = getattr(results.tasks_output[2], "raw", "No details available.")
|
543 |
-
if writer_output and writer_output.strip():
|
544 |
-
st.markdown("### Final Report")
|
545 |
-
st.write(writer_output)
|
546 |
-
else:
|
547 |
-
st.warning("No final report available.")
|
548 |
|
549 |
-
#
|
550 |
-
|
551 |
-
tab1, tab2 = st.tabs(["Planner's Insights", "Analyst's Analysis"])
|
552 |
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
if planner_output and planner_output.strip():
|
557 |
-
st.write(planner_output)
|
558 |
-
else:
|
559 |
-
st.warning("No planner insights available.")
|
560 |
|
561 |
-
#
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
566 |
|
567 |
-
|
568 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
569 |
st.subheader("Structured Analyst Output")
|
570 |
st.write(data_insights)
|
|
|
|
|
571 |
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
# Display Data Tables
|
580 |
-
table_data = display_table(data_insights)
|
581 |
|
|
|
|
|
|
|
582 |
else:
|
583 |
-
st.
|
|
|
|
|
584 |
|
585 |
# Notify user that the analysis is complete
|
586 |
-
st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
|
587 |
|
588 |
-
#
|
589 |
if writer_output:
|
590 |
pdf_path = generate_pdf_report(
|
591 |
result=writer_output,
|
592 |
charts=charts,
|
593 |
table_data=data_insights,
|
594 |
metadata={"Technology Area": patent_area, "Stakeholder": stakeholder},
|
595 |
-
key_insights=key_insights
|
596 |
)
|
597 |
|
598 |
# Download button for the generated PDF
|
@@ -604,9 +627,9 @@ if st.button("Generate Patent Insights"):
|
|
604 |
mime="application/pdf"
|
605 |
)
|
606 |
else:
|
607 |
-
st.warning("Report generation skipped due to missing content.")
|
608 |
|
609 |
except Exception as e:
|
610 |
error_message = traceback.format_exc()
|
611 |
logging.error(f"An error occurred during execution:\n{error_message}")
|
612 |
-
st.error(f"β οΈ An unexpected error occurred:\n{e}")
|
|
|
528 |
# Start the timer
|
529 |
start_time = time.time()
|
530 |
|
531 |
+
# Validate user inputs
|
532 |
if not patent_area or not stakeholder:
|
533 |
st.error("Please provide both Patent Technology Area and Stakeholder.")
|
534 |
+
st.stop()
|
535 |
+
|
536 |
+
# Log and execute the analysis
|
537 |
+
logging.info(f"Starting analysis with Topic: {patent_area}, Stakeholder: {stakeholder}")
|
538 |
+
results = crew.kickoff(inputs={"topic": patent_area, "stakeholder": stakeholder})
|
539 |
|
540 |
# Calculate elapsed time
|
541 |
elapsed_time = time.time() - start_time
|
542 |
|
543 |
+
# Extract Outputs
|
544 |
+
planner_output = getattr(results.tasks_output[0], "raw", "No details available.")
|
545 |
+
analyst_output = getattr(results.tasks_output[1], "raw", "No details available.")
|
546 |
writer_output = getattr(results.tasks_output[2], "raw", "No details available.")
|
|
|
|
|
|
|
|
|
|
|
547 |
|
548 |
+
# Initialize empty variables to avoid undefined errors
|
549 |
+
key_insights, data_insights, charts, table_data = [], [], [], []
|
|
|
550 |
|
551 |
+
# Parse Analyst Output (Key Insights + Data Insights)
|
552 |
+
if analyst_output and analyst_output.strip():
|
553 |
+
key_insights, data_insights = parse_analyst_output(analyst_output)
|
|
|
|
|
|
|
|
|
554 |
|
555 |
+
# Generate visualizations and tables if enabled
|
556 |
+
if enable_advanced_analysis and data_insights:
|
557 |
+
charts = create_visualizations(data_insights)
|
558 |
+
table_data = display_table(data_insights)
|
559 |
+
else:
|
560 |
+
st.info("No data insights available for visualizations.")
|
561 |
+
|
562 |
+
# Unified Tabs for Final Report, Planner, and Analyst Outputs
|
563 |
+
tab1, tab2, tab3 = st.tabs(["π Final Report", "π Planner's Insights", "π Analyst's Analysis"])
|
564 |
+
|
565 |
+
# Final Report Tab
|
566 |
+
with tab1:
|
567 |
+
st.subheader("π Final Report")
|
568 |
+
if writer_output and writer_output.strip():
|
569 |
+
st.write(writer_output)
|
570 |
+
else:
|
571 |
+
st.warning("No final report available.")
|
572 |
|
573 |
+
# Planner's Insights Tab
|
574 |
+
with tab2:
|
575 |
+
st.subheader("π Planner's Insights")
|
576 |
+
if planner_output and planner_output.strip():
|
577 |
+
st.write(planner_output)
|
578 |
+
else:
|
579 |
+
st.warning("No planner insights available.")
|
580 |
+
|
581 |
+
# Analyst's Analysis Tab
|
582 |
+
with tab3:
|
583 |
+
st.subheader("π Analyst's Analysis")
|
584 |
+
if analyst_output and analyst_output.strip():
|
585 |
+
st.write(analyst_output)
|
586 |
+
|
587 |
+
if data_insights:
|
588 |
st.subheader("Structured Analyst Output")
|
589 |
st.write(data_insights)
|
590 |
+
else:
|
591 |
+
st.info("No structured data insights available.")
|
592 |
|
593 |
+
if charts:
|
594 |
+
st.subheader("Generated Visualizations")
|
595 |
+
for chart_path in charts:
|
596 |
+
st.image(chart_path, caption="Generated Chart", use_column_width=True)
|
597 |
+
else:
|
598 |
+
st.info("No charts available for display.")
|
|
|
|
|
|
|
599 |
|
600 |
+
if table_data:
|
601 |
+
st.subheader("Data Tables")
|
602 |
+
st.write(table_data)
|
603 |
else:
|
604 |
+
st.info("No tables available for display.")
|
605 |
+
else:
|
606 |
+
st.warning("No analyst analysis available.")
|
607 |
|
608 |
# Notify user that the analysis is complete
|
609 |
+
st.success(f"β
Analysis completed in {elapsed_time:.2f} seconds.")
|
610 |
|
611 |
+
# PDF Report Generation
|
612 |
if writer_output:
|
613 |
pdf_path = generate_pdf_report(
|
614 |
result=writer_output,
|
615 |
charts=charts,
|
616 |
table_data=data_insights,
|
617 |
metadata={"Technology Area": patent_area, "Stakeholder": stakeholder},
|
618 |
+
key_insights=key_insights
|
619 |
)
|
620 |
|
621 |
# Download button for the generated PDF
|
|
|
627 |
mime="application/pdf"
|
628 |
)
|
629 |
else:
|
630 |
+
st.warning("β οΈ Report generation skipped due to missing content.")
|
631 |
|
632 |
except Exception as e:
|
633 |
error_message = traceback.format_exc()
|
634 |
logging.error(f"An error occurred during execution:\n{error_message}")
|
635 |
+
st.error(f"β οΈ An unexpected error occurred:\n{e}")
|