Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -528,94 +528,71 @@ 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 |
-
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
|
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 |
-
#
|
549 |
-
|
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 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
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 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
|
587 |
-
|
|
|
588 |
st.subheader("Structured Analyst Output")
|
589 |
st.write(data_insights)
|
590 |
-
else:
|
591 |
-
st.info("No structured data insights available.")
|
592 |
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
|
|
|
|
|
|
599 |
|
600 |
-
if table_data:
|
601 |
-
st.subheader("Data Tables")
|
602 |
-
st.write(table_data)
|
603 |
else:
|
604 |
-
st.
|
605 |
-
else:
|
606 |
-
st.warning("No analyst analysis available.")
|
607 |
|
608 |
# Notify user that the analysis is complete
|
609 |
-
st.success(f"
|
610 |
|
611 |
-
# PDF
|
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,9 +604,9 @@ if st.button("Generate Patent Insights"):
|
|
627 |
mime="application/pdf"
|
628 |
)
|
629 |
else:
|
630 |
-
st.warning("
|
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}")
|
|
|
528 |
# Start the timer
|
529 |
start_time = time.time()
|
530 |
|
531 |
+
# Kick off the crew with user inputs
|
532 |
if not patent_area or not stakeholder:
|
533 |
st.error("Please provide both Patent Technology Area and Stakeholder.")
|
534 |
+
else:
|
535 |
+
logging.info(f"Starting analysis with Topic: {patent_area}, Stakeholder: {stakeholder}")
|
536 |
+
results = crew.kickoff(inputs={"topic": patent_area, "stakeholder": stakeholder})
|
|
|
|
|
537 |
|
538 |
# Calculate elapsed time
|
539 |
elapsed_time = time.time() - start_time
|
540 |
|
541 |
+
# Extract Writer's Output
|
|
|
|
|
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 |
+
# Expandable section for detailed insights
|
550 |
+
with st.expander("Explore Detailed Insights"):
|
551 |
+
tab1, tab2 = st.tabs(["Planner's Insights", "Analyst's Analysis"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
552 |
|
553 |
+
# Planner's Insights
|
554 |
+
with tab1:
|
555 |
+
planner_output = getattr(results.tasks_output[0], "raw", "No details available.")
|
556 |
+
if planner_output and planner_output.strip():
|
557 |
+
st.write(planner_output)
|
558 |
+
else:
|
559 |
+
st.warning("No planner insights available.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
|
561 |
+
# Analyst's Analysis
|
562 |
+
with tab2:
|
563 |
+
analyst_output = getattr(results.tasks_output[1], "raw", "No details available.")
|
564 |
+
if analyst_output and analyst_output.strip():
|
565 |
+
st.write(analyst_output)
|
566 |
|
567 |
+
# Parse Analyst Output (Key Insights + Data Insights)
|
568 |
+
key_insights, data_insights = parse_analyst_output(analyst_output)
|
569 |
st.subheader("Structured Analyst Output")
|
570 |
st.write(data_insights)
|
|
|
|
|
571 |
|
572 |
+
# Create Visualizations if enabled
|
573 |
+
charts = []
|
574 |
+
if enable_advanced_analysis and data_insights:
|
575 |
+
charts = create_visualizations(data_insights)
|
576 |
+
else:
|
577 |
+
st.info("No data insights available for visualizations.")
|
578 |
+
|
579 |
+
# Display Data Tables
|
580 |
+
table_data = display_table(data_insights)
|
581 |
|
|
|
|
|
|
|
582 |
else:
|
583 |
+
st.warning("No analyst analysis available.")
|
|
|
|
|
584 |
|
585 |
# Notify user that the analysis is complete
|
586 |
+
st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
|
587 |
|
588 |
+
# Generate the PDF report with Key Insights and Data Insights
|
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 # Pass key insights to the PDF
|
596 |
)
|
597 |
|
598 |
# Download button for the generated PDF
|
|
|
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}")
|