DrishtiSharma commited on
Commit
3b037e4
·
verified ·
1 Parent(s): 73cb56f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -31
app.py CHANGED
@@ -416,7 +416,7 @@ if st.button("Generate Patent Insights"):
416
 
417
  # Extract Writer's Output
418
  writer_output = getattr(results.tasks_output[2], "raw", "No details available.")
419
- if writer_output:
420
  st.markdown("### Final Report")
421
  st.write(writer_output)
422
  else:
@@ -429,48 +429,60 @@ if st.button("Generate Patent Insights"):
429
  # Planner's Insights
430
  with tab1:
431
  planner_output = getattr(results.tasks_output[0], "raw", "No details available.")
432
- st.write(planner_output)
 
 
 
433
 
434
  # Analyst's Analysis
435
  with tab2:
436
  analyst_output = getattr(results.tasks_output[1], "raw", "No details available.")
437
- st.write(analyst_output)
 
438
 
439
- # Convert raw analyst output into structured key/data insights
440
- key_insights, data_insights = parse_analyst_output(analyst_output)
441
- st.subheader("Structured Analyst Output")
442
- st.write(data_insights)
443
 
444
- # Create Visualizations if enabled
445
- charts = []
446
- if enable_advanced_analysis:
447
- charts = create_visualizations(data_insights)
 
 
448
 
449
- # Display Data Tables
450
- table_data = display_table(data_insights)
451
 
452
- # Notify that analysis is complete
 
 
 
453
  st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
454
 
455
  # Generate the PDF report with Key Insights and Data Insights
456
- pdf_path = generate_pdf_report(
457
- result=writer_output,
458
- charts=charts,
459
- table_data=data_insights,
460
- metadata={"Technology Area": patent_area, "Stakeholder": stakeholder},
461
- key_insights=key_insights # 🔑 Pass key insights to the PDF
462
- )
463
-
464
- # Download button for the generated PDF
465
- with open(pdf_path, "rb") as report_file:
466
- st.download_button(
467
- label="Download Report",
468
- data=report_file,
469
- file_name="Patent_Strategy_Report.pdf",
470
- mime="application/pdf"
471
  )
472
 
 
 
 
 
 
 
 
 
 
 
 
473
  except Exception as e:
474
- # Handle errors
475
  logging.error(f"An error occurred during execution: {e}")
476
- st.error(f"An error occurred during execution: {e}")
 
416
 
417
  # Extract Writer's Output
418
  writer_output = getattr(results.tasks_output[2], "raw", "No details available.")
419
+ if writer_output and writer_output.strip():
420
  st.markdown("### Final Report")
421
  st.write(writer_output)
422
  else:
 
429
  # Planner's Insights
430
  with tab1:
431
  planner_output = getattr(results.tasks_output[0], "raw", "No details available.")
432
+ if planner_output and planner_output.strip():
433
+ st.write(planner_output)
434
+ else:
435
+ st.warning("No planner insights available.")
436
 
437
  # Analyst's Analysis
438
  with tab2:
439
  analyst_output = getattr(results.tasks_output[1], "raw", "No details available.")
440
+ if analyst_output and analyst_output.strip():
441
+ st.write(analyst_output)
442
 
443
+ # Parse Analyst Output (Key Insights + Data Insights)
444
+ key_insights, data_insights = parse_analyst_output(analyst_output)
445
+ st.subheader("Structured Analyst Output")
446
+ st.write(data_insights)
447
 
448
+ # Create Visualizations if enabled
449
+ charts = []
450
+ if enable_advanced_analysis and data_insights:
451
+ charts = create_visualizations(data_insights)
452
+ else:
453
+ st.info("No data insights available for visualizations.")
454
 
455
+ # Display Data Tables
456
+ table_data = display_table(data_insights)
457
 
458
+ else:
459
+ st.warning("No analyst analysis available.")
460
+
461
+ # Notify user that the analysis is complete
462
  st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
463
 
464
  # Generate the PDF report with Key Insights and Data Insights
465
+ if writer_output:
466
+ pdf_path = generate_pdf_report(
467
+ result=writer_output,
468
+ charts=charts,
469
+ table_data=data_insights,
470
+ metadata={"Technology Area": patent_area, "Stakeholder": stakeholder},
471
+ key_insights=key_insights # 🔑 Pass key insights to the PDF
 
 
 
 
 
 
 
 
472
  )
473
 
474
+ # Download button for the generated PDF
475
+ with open(pdf_path, "rb") as report_file:
476
+ st.download_button(
477
+ label="📄 Download Report",
478
+ data=report_file,
479
+ file_name="Patent_Strategy_Report.pdf",
480
+ mime="application/pdf"
481
+ )
482
+ else:
483
+ st.warning("Report generation skipped due to missing content.")
484
+
485
  except Exception as e:
486
+ # Error Handling
487
  logging.error(f"An error occurred during execution: {e}")
488
+ st.error("⚠️ An unexpected error occurred. Please try again.")