DrishtiSharma commited on
Commit
56f1eb3
Β·
verified Β·
1 Parent(s): 8815891

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -33
app.py CHANGED
@@ -457,6 +457,8 @@ def generate_visuals(query, df, llm, result_container, progress_bar, step):
457
  progress_bar.progress(step + 1, text="βœ… Visualizations Ready!")
458
 
459
 
 
 
460
  # SQL-RAG Analysis
461
  if st.session_state.df is not None:
462
  temp_dir = tempfile.TemporaryDirectory()
@@ -530,7 +532,7 @@ if st.session_state.df is not None:
530
  )
531
 
532
  write_report = Task(
533
- description="Write the analysis report with Introduction and Key Insights. DO NOT include any Conclusion or Summary.",
534
  expected_output="Markdown-formatted report excluding Conclusion.",
535
  agent=report_writer,
536
  context=[analyze_data],
@@ -538,14 +540,12 @@ if st.session_state.df is not None:
538
 
539
  write_conclusion = Task(
540
  description="Summarize the key findings in 3-5 impactful lines, highlighting the maximum, minimum, and average salaries."
541
- "Emphasize significant insights on salary distribution and influential compensation trends for strategic decision-making.",
542
  expected_output="Markdown-formatted Conclusion section with key insights and statistics.",
543
  agent=conclusion_writer,
544
  context=[analyze_data],
545
  )
546
 
547
-
548
-
549
  # Separate Crews for report and conclusion
550
  crew_report = Crew(
551
  agents=[sql_dev, data_analyst, report_writer],
@@ -568,38 +568,60 @@ if st.session_state.df is not None:
568
  with tab1:
569
  query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
570
  if st.button("Submit Query"):
571
- with st.spinner("Processing query..."):
572
- # Step 1: Generate the analysis report
 
 
 
 
573
  report_inputs = {"query": query + " Provide detailed analysis but DO NOT include Conclusion."}
574
- report_result = crew_report.kickoff(inputs=report_inputs)
 
575
 
576
- # Step 2: Generate only the concise conclusion
 
577
  conclusion_inputs = {"query": query + " Provide ONLY the most important insights in 3-5 concise lines."}
578
- conclusion_result = crew_conclusion.kickoff(inputs=conclusion_inputs)
579
-
580
- # Step 3: Display the report
581
- #st.markdown("### Analysis Report:")
582
- st.markdown(report_result if report_result else "⚠️ No Report Generated.")
583
-
584
- # Step 4: Suggest Visualizations
585
- visualization_suggestions = ask_gpt4o_for_visualization(query, st.session_state.df, llm)
586
-
587
-
588
-
589
- # Step 5: Insert Visual Insights
590
- st.markdown("### Visual Insights")
591
- if visualization_suggestions:
592
- handle_visualization_suggestions(visualization_suggestions, st.session_state.df)
593
- else:
594
- st.warning("⚠️ No suitable visualizations to display.")
595
-
596
-
597
-
598
- # Step 6: Display Concise Conclusion
599
- #st.markdown("#### Conclusion")
600
-
601
- safe_conclusion = escape_markdown(conclusion_result if conclusion_result else "⚠️ No Conclusion Generated.")
602
- st.markdown(safe_conclusion)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
603
 
604
 
605
  # Sidebar Reference
 
457
  progress_bar.progress(step + 1, text="βœ… Visualizations Ready!")
458
 
459
 
460
+ import threading
461
+
462
  # SQL-RAG Analysis
463
  if st.session_state.df is not None:
464
  temp_dir = tempfile.TemporaryDirectory()
 
532
  )
533
 
534
  write_report = Task(
535
+ description="Write the analysis report with Introduction and Key Insights. DO NOT include any Conclusion or Summary.",
536
  expected_output="Markdown-formatted report excluding Conclusion.",
537
  agent=report_writer,
538
  context=[analyze_data],
 
540
 
541
  write_conclusion = Task(
542
  description="Summarize the key findings in 3-5 impactful lines, highlighting the maximum, minimum, and average salaries."
543
+ "Emphasize significant insights on salary distribution and influential compensation trends for strategic decision-making.",
544
  expected_output="Markdown-formatted Conclusion section with key insights and statistics.",
545
  agent=conclusion_writer,
546
  context=[analyze_data],
547
  )
548
 
 
 
549
  # Separate Crews for report and conclusion
550
  crew_report = Crew(
551
  agents=[sql_dev, data_analyst, report_writer],
 
568
  with tab1:
569
  query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
570
  if st.button("Submit Query"):
571
+ result_container = {"report": None, "conclusion": None, "visuals": None}
572
+ progress_bar = st.progress(0, text="πŸš€ Starting Analysis...")
573
+
574
+ # Define parallel tasks
575
+ def generate_report():
576
+ progress_bar.progress(20, text="πŸ“ Generating Analysis Report...")
577
  report_inputs = {"query": query + " Provide detailed analysis but DO NOT include Conclusion."}
578
+ result_container['report'] = crew_report.kickoff(inputs=report_inputs)
579
+ progress_bar.progress(40, text="βœ… Analysis Report Ready!")
580
 
581
+ def generate_conclusion():
582
+ progress_bar.progress(40, text="πŸ“ Crafting Conclusion...")
583
  conclusion_inputs = {"query": query + " Provide ONLY the most important insights in 3-5 concise lines."}
584
+ result_container['conclusion'] = crew_conclusion.kickoff(inputs=conclusion_inputs)
585
+ progress_bar.progress(60, text="βœ… Conclusion Ready!")
586
+
587
+ def generate_visuals():
588
+ progress_bar.progress(60, text="πŸ“Š Creating Visualizations...")
589
+ result_container['visuals'] = ask_gpt4o_for_visualization(query, st.session_state.df, llm)
590
+ progress_bar.progress(80, text="βœ… Visualizations Ready!")
591
+
592
+ # Run tasks in parallel
593
+ thread_report = threading.Thread(target=generate_report)
594
+ thread_conclusion = threading.Thread(target=generate_conclusion)
595
+ thread_visuals = threading.Thread(target=generate_visuals)
596
+
597
+ thread_report.start()
598
+ thread_conclusion.start()
599
+ thread_visuals.start()
600
+
601
+ # Wait for all threads to finish
602
+ thread_report.join()
603
+ thread_conclusion.join()
604
+ thread_visuals.join()
605
+
606
+ progress_bar.progress(100, text="βœ… Full Analysis Complete!")
607
+ time.sleep(0.5)
608
+ progress_bar.empty()
609
+
610
+ # Display Report
611
+ st.markdown("## πŸ“Š Analysis Report")
612
+ st.markdown(result_container['report'] if result_container['report'] else "⚠️ No Report Generated.")
613
+
614
+ # Display Visual Insights
615
+ st.markdown("## πŸ“ˆ Visual Insights")
616
+ if result_container['visuals']:
617
+ handle_visualization_suggestions(result_container['visuals'], st.session_state.df)
618
+ else:
619
+ st.warning("⚠️ No suitable visualizations to display.")
620
+
621
+ # Display Conclusion
622
+ st.markdown("## πŸ“ Conclusion")
623
+ safe_conclusion = escape_markdown(result_container['conclusion'] if result_container['conclusion'] else "⚠️ No Conclusion Generated.")
624
+ st.markdown(safe_conclusion)
625
 
626
 
627
  # Sidebar Reference