Update app.py
Browse files
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
|
| 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 |
-
|
| 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 |
-
|
| 572 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 573 |
report_inputs = {"query": query + " Provide detailed analysis but DO NOT include Conclusion."}
|
| 574 |
-
|
|
|
|
| 575 |
|
| 576 |
-
|
|
|
|
| 577 |
conclusion_inputs = {"query": query + " Provide ONLY the most important insights in 3-5 concise lines."}
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|