Update app.py
Browse files
app.py
CHANGED
@@ -85,6 +85,8 @@ if st.session_state.df is not None and st.session_state.show_preview:
|
|
85 |
|
86 |
# SQL-RAG Analysis
|
87 |
if st.session_state.df is not None:
|
|
|
|
|
88 |
temp_dir = tempfile.TemporaryDirectory()
|
89 |
db_path = os.path.join(temp_dir.name, "data.db")
|
90 |
connection = sqlite3.connect(db_path)
|
@@ -139,7 +141,10 @@ if st.session_state.df is not None:
|
|
139 |
# New Agent for generating ONLY the Conclusion
|
140 |
conclusion_writer = Agent(
|
141 |
role="Conclusion Specialist",
|
142 |
-
goal=
|
|
|
|
|
|
|
143 |
backstory="An expert in crafting well-structured and insightful conclusions.",
|
144 |
llm=llm,
|
145 |
)
|
@@ -166,8 +171,11 @@ if st.session_state.df is not None:
|
|
166 |
)
|
167 |
|
168 |
write_conclusion = Task(
|
169 |
-
description=
|
170 |
-
|
|
|
|
|
|
|
171 |
agent=conclusion_writer,
|
172 |
context=[analyze_data],
|
173 |
)
|
@@ -188,7 +196,7 @@ if st.session_state.df is not None:
|
|
188 |
query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
|
189 |
if st.button("Submit Query"):
|
190 |
with st.spinner("Processing query..."):
|
191 |
-
# Step 1: Generate
|
192 |
report_inputs = {"query": query + " Provide a detailed analysis but DO NOT include a Conclusion."}
|
193 |
report_result = crew.kickoff(inputs=report_inputs)
|
194 |
|
@@ -196,9 +204,9 @@ if st.session_state.df is not None:
|
|
196 |
conclusion_inputs = {"query": query + " Now, provide only the Conclusion for this analysis."}
|
197 |
conclusion_result = crew.kickoff(inputs=conclusion_inputs)
|
198 |
|
199 |
-
#
|
200 |
-
main_report = report_result
|
201 |
-
conclusion = conclusion_result
|
202 |
|
203 |
st.markdown("### Analysis Report:")
|
204 |
st.markdown(main_report)
|
@@ -252,8 +260,7 @@ if st.session_state.df is not None:
|
|
252 |
else:
|
253 |
st.info("Please load a dataset to proceed.")
|
254 |
|
255 |
-
|
256 |
# Sidebar Reference
|
257 |
with st.sidebar:
|
258 |
st.header("๐ Reference:")
|
259 |
-
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)")
|
|
|
85 |
|
86 |
# SQL-RAG Analysis
|
87 |
if st.session_state.df is not None:
|
88 |
+
import numpy as np
|
89 |
+
|
90 |
temp_dir = tempfile.TemporaryDirectory()
|
91 |
db_path = os.path.join(temp_dir.name, "data.db")
|
92 |
connection = sqlite3.connect(db_path)
|
|
|
141 |
# New Agent for generating ONLY the Conclusion
|
142 |
conclusion_writer = Agent(
|
143 |
role="Conclusion Specialist",
|
144 |
+
goal=(
|
145 |
+
"Generate a concise 3-5 line conclusion including the maximum, minimum, and average salary "
|
146 |
+
"of Principal Data Scientists. Highlight how geography, experience, and employment type impact salary."
|
147 |
+
),
|
148 |
backstory="An expert in crafting well-structured and insightful conclusions.",
|
149 |
llm=llm,
|
150 |
)
|
|
|
171 |
)
|
172 |
|
173 |
write_conclusion = Task(
|
174 |
+
description=(
|
175 |
+
"Summarize the findings into a concise Conclusion. Include the max, min, and average salary in USD, "
|
176 |
+
"and highlight the most impactful insights."
|
177 |
+
),
|
178 |
+
expected_output="Markdown-formatted Conclusion section with key statistics.",
|
179 |
agent=conclusion_writer,
|
180 |
context=[analyze_data],
|
181 |
)
|
|
|
196 |
query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
|
197 |
if st.button("Submit Query"):
|
198 |
with st.spinner("Processing query..."):
|
199 |
+
# Step 1: Generate the main report (without Conclusion)
|
200 |
report_inputs = {"query": query + " Provide a detailed analysis but DO NOT include a Conclusion."}
|
201 |
report_result = crew.kickoff(inputs=report_inputs)
|
202 |
|
|
|
204 |
conclusion_inputs = {"query": query + " Now, provide only the Conclusion for this analysis."}
|
205 |
conclusion_result = crew.kickoff(inputs=conclusion_inputs)
|
206 |
|
207 |
+
# Handle Crew Output safely
|
208 |
+
main_report = getattr(report_result, 'output', "โ ๏ธ No Report Generated.")
|
209 |
+
conclusion = getattr(conclusion_result, 'output', "โ ๏ธ No Conclusion Generated.")
|
210 |
|
211 |
st.markdown("### Analysis Report:")
|
212 |
st.markdown(main_report)
|
|
|
260 |
else:
|
261 |
st.info("Please load a dataset to proceed.")
|
262 |
|
|
|
263 |
# Sidebar Reference
|
264 |
with st.sidebar:
|
265 |
st.header("๐ Reference:")
|
266 |
+
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)")
|