DrishtiSharma commited on
Commit
3af1043
Β·
verified Β·
1 Parent(s): b945491

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -46
app.py CHANGED
@@ -546,69 +546,54 @@ if st.session_state.df is not None:
546
  )
547
 
548
  # Tabs for Query Results and Visualizations
549
- tab1, tab2 = st.tabs(["πŸ” Query Insights + Viz", "πŸ“Š Full Data Viz"])
550
 
551
  # Query Insights + Visualization
552
  with tab1:
553
  query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
554
  if st.button("Submit Query"):
555
- result_container = {"report": None, "conclusion": None, "visuals": None}
556
- progress_bar = st.progress(0, text="πŸš€ Starting Analysis...")
557
-
558
- # Define parallel tasks
559
- def generate_report():
560
- progress_bar.progress(20, text="πŸ“ Generating Analysis Report...")
561
  report_inputs = {"query": query + " Provide detailed analysis but DO NOT include Conclusion."}
562
- result_container['report'] = crew_report.kickoff(inputs=report_inputs)
563
- progress_bar.progress(40, text="βœ… Analysis Report Ready!")
564
 
565
- def generate_conclusion():
566
- progress_bar.progress(40, text="πŸ“ Crafting Conclusion...")
567
  conclusion_inputs = {"query": query + " Provide ONLY the most important insights in 3-5 concise lines."}
568
- result_container['conclusion'] = crew_conclusion.kickoff(inputs=conclusion_inputs)
569
- progress_bar.progress(60, text="βœ… Conclusion Ready!")
570
-
571
- def generate_visuals():
572
- progress_bar.progress(60, text="πŸ“Š Creating Visualizations...")
573
- result_container['visuals'] = ask_gpt4o_for_visualization(query, st.session_state.df, llm)
574
- progress_bar.progress(80, text="βœ… Visualizations Ready!")
575
 
576
- # Run tasks in parallel
577
- thread_report = threading.Thread(target=generate_report)
578
- thread_conclusion = threading.Thread(target=generate_conclusion)
579
- thread_visuals = threading.Thread(target=generate_visuals)
580
 
581
- thread_report.start()
582
- thread_conclusion.start()
583
- thread_visuals.start()
584
 
585
- # Wait for all threads to finish
586
- thread_report.join()
587
- thread_conclusion.join()
588
- thread_visuals.join()
589
 
590
- progress_bar.progress(100, text="βœ… Full Analysis Complete!")
591
- time.sleep(0.5)
592
- progress_bar.empty()
 
 
 
593
 
594
- # Display Report
595
- st.markdown("## πŸ“Š Analysis Report")
596
- st.markdown(result_container['report'] if result_container['report'] else "⚠️ No Report Generated.")
597
 
598
- # Display Visual Insights
599
- st.markdown("## πŸ“ˆ Visual Insights")
600
- if result_container['visuals']:
601
- handle_visualization_suggestions(result_container['visuals'], st.session_state.df)
602
- else:
603
- st.warning("⚠️ No suitable visualizations to display.")
604
 
605
- # Display Conclusion
606
- st.markdown("## πŸ“ Conclusion")
607
- safe_conclusion = escape_markdown(result_container['conclusion'] if result_container['conclusion'] else "⚠️ No Conclusion Generated.")
608
- st.markdown(safe_conclusion)
609
 
610
 
611
  # Sidebar Reference
612
  with st.sidebar:
613
  st.header("πŸ“š Reference:")
614
- st.markdown("[SQL Agents w CrewAI & Llama 3 - Plaban Nayak](https://github.com/plaban1981/Agents/blob/main/SQL_Agents_with_CrewAI_and_Llama_3.ipynb)")
 
546
  )
547
 
548
  # Tabs for Query Results and Visualizations
549
+ tab1 = st.tabs(["πŸ” Query Insights + Viz", "πŸ“Š Full Data Viz"])
550
 
551
  # Query Insights + Visualization
552
  with tab1:
553
  query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
554
  if st.button("Submit Query"):
555
+ with st.spinner("Processing query..."):
556
+ # Step 1: Generate the analysis report
 
 
 
 
557
  report_inputs = {"query": query + " Provide detailed analysis but DO NOT include Conclusion."}
558
+ report_result = crew_report.kickoff(inputs=report_inputs)
 
559
 
560
+ # Step 2: Generate only the concise conclusion
 
561
  conclusion_inputs = {"query": query + " Provide ONLY the most important insights in 3-5 concise lines."}
562
+ conclusion_result = crew_conclusion.kickoff(inputs=conclusion_inputs)
 
 
 
 
 
 
563
 
564
+ # Step 3: Display the report
565
+ #st.markdown("### Analysis Report:")
566
+ st.markdown(report_result if report_result else "⚠️ No Report Generated.")
 
567
 
568
+ # Step 4: Generate Visualizations
569
+ visualizations = []
 
570
 
571
+ fig_salary = px.box(st.session_state.df, x="job_title", y="salary_in_usd",
572
+ title="Salary Distribution by Job Title")
573
+ visualizations.append(fig_salary)
 
574
 
575
+ fig_experience = px.bar(
576
+ st.session_state.df.groupby("experience_level")["salary_in_usd"].mean().reset_index(),
577
+ x="experience_level", y="salary_in_usd",
578
+ title="Average Salary by Experience Level"
579
+ )
580
+ visualizations.append(fig_experience)
581
 
582
+ fig_employment = px.box(st.session_state.df, x="employment_type", y="salary_in_usd",
583
+ title="Salary Distribution by Employment Type")
584
+ visualizations.append(fig_employment)
585
 
586
+ # Step 5: Insert Visual Insights
587
+ st.markdown("### Visual Insights")
588
+ for fig in visualizations:
589
+ st.plotly_chart(fig, use_container_width=True)
 
 
590
 
591
+ # Step 6: Display Concise Conclusion
592
+ #st.markdown("#### Conclusion")
593
+ st.markdown(conclusion_result if conclusion_result else "⚠�� No Conclusion Generated.")
 
594
 
595
 
596
  # Sidebar Reference
597
  with st.sidebar:
598
  st.header("πŸ“š Reference:")
599
+ st.markdown("[SQL Agents w CrewAI & Llama 3 - Plaban Nayak](https://github.com/plaban1981/Agents/blob/main/SQL_Agents_with_CrewAI_and_Llama_3.ipynb)")