Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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 |
-
|
556 |
-
|
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 |
-
|
563 |
-
progress_bar.progress(40, text="β
Analysis Report Ready!")
|
564 |
|
565 |
-
|
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 |
-
|
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 |
-
|
577 |
-
|
578 |
-
|
579 |
-
thread_visuals = threading.Thread(target=generate_visuals)
|
580 |
|
581 |
-
|
582 |
-
|
583 |
-
thread_visuals.start()
|
584 |
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
thread_visuals.join()
|
589 |
|
590 |
-
|
591 |
-
|
592 |
-
|
|
|
|
|
|
|
593 |
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
else:
|
603 |
-
st.warning("β οΈ No suitable visualizations to display.")
|
604 |
|
605 |
-
|
606 |
-
|
607 |
-
|
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)")
|