Spaces:
Sleeping
Sleeping
DrishtiSharma
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -85,8 +85,6 @@ 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 |
-
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,15 +139,12 @@ if st.session_state.df is not None:
|
|
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 |
)
|
151 |
|
152 |
-
# Tasks for
|
153 |
extract_data = Task(
|
154 |
description="Extract data based on the query: {query}.",
|
155 |
expected_output="Database results matching the query.",
|
@@ -170,28 +165,17 @@ if st.session_state.df is not None:
|
|
170 |
context=[analyze_data],
|
171 |
)
|
172 |
|
173 |
-
# Task for Conclusion
|
174 |
write_conclusion = Task(
|
175 |
-
description=
|
176 |
-
|
177 |
-
"and highlight the most impactful insights."
|
178 |
-
),
|
179 |
-
expected_output="Markdown-formatted Conclusion section with key statistics.",
|
180 |
agent=conclusion_writer,
|
181 |
context=[analyze_data],
|
182 |
)
|
183 |
|
184 |
-
#
|
185 |
-
|
186 |
-
agents=[sql_dev, data_analyst, report_writer],
|
187 |
-
tasks=[extract_data, analyze_data, write_report],
|
188 |
-
process=Process.sequential,
|
189 |
-
verbose=True,
|
190 |
-
)
|
191 |
-
|
192 |
-
crew_conclusion = Crew(
|
193 |
-
agents=[data_analyst, conclusion_writer],
|
194 |
-
tasks=[write_conclusion],
|
195 |
process=Process.sequential,
|
196 |
verbose=True,
|
197 |
)
|
@@ -204,17 +188,17 @@ if st.session_state.df is not None:
|
|
204 |
query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
|
205 |
if st.button("Submit Query"):
|
206 |
with st.spinner("Processing query..."):
|
207 |
-
# Step 1: Generate
|
208 |
-
report_inputs = {"query": query}
|
209 |
-
report_result =
|
210 |
|
211 |
# Step 2: Generate only the Conclusion
|
212 |
-
conclusion_inputs = {"query": query}
|
213 |
-
conclusion_result =
|
214 |
|
215 |
-
#
|
216 |
-
main_report = report_result
|
217 |
-
conclusion = conclusion_result
|
218 |
|
219 |
st.markdown("### Analysis Report:")
|
220 |
st.markdown(main_report)
|
@@ -272,4 +256,5 @@ else:
|
|
272 |
# Sidebar Reference
|
273 |
with st.sidebar:
|
274 |
st.header("๐ Reference:")
|
275 |
-
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 |
temp_dir = tempfile.TemporaryDirectory()
|
89 |
db_path = os.path.join(temp_dir.name, "data.db")
|
90 |
connection = sqlite3.connect(db_path)
|
|
|
139 |
# New Agent for generating ONLY the Conclusion
|
140 |
conclusion_writer = Agent(
|
141 |
role="Conclusion Specialist",
|
142 |
+
goal="Summarize findings into a clear and concise Conclusion/Summary section.",
|
|
|
|
|
|
|
143 |
backstory="An expert in crafting well-structured and insightful conclusions.",
|
144 |
llm=llm,
|
145 |
)
|
146 |
|
147 |
+
# Tasks for each agent
|
148 |
extract_data = Task(
|
149 |
description="Extract data based on the query: {query}.",
|
150 |
expected_output="Database results matching the query.",
|
|
|
165 |
context=[analyze_data],
|
166 |
)
|
167 |
|
|
|
168 |
write_conclusion = Task(
|
169 |
+
description="Summarize the findings into a concise Conclusion.",
|
170 |
+
expected_output="Markdown-formatted Conclusion section.",
|
|
|
|
|
|
|
171 |
agent=conclusion_writer,
|
172 |
context=[analyze_data],
|
173 |
)
|
174 |
|
175 |
+
# Crew setup
|
176 |
+
crew = Crew(
|
177 |
+
agents=[sql_dev, data_analyst, report_writer, conclusion_writer],
|
178 |
+
tasks=[extract_data, analyze_data, write_report, write_conclusion],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
process=Process.sequential,
|
180 |
verbose=True,
|
181 |
)
|
|
|
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 Report without Conclusion
|
192 |
+
report_inputs = {"query": query + " Provide a detailed analysis but DO NOT include a Conclusion."}
|
193 |
+
report_result = crew.kickoff(inputs=report_inputs)
|
194 |
|
195 |
# Step 2: Generate only the Conclusion
|
196 |
+
conclusion_inputs = {"query": query + " Now, provide only the Conclusion for this analysis."}
|
197 |
+
conclusion_result = crew.kickoff(inputs=conclusion_inputs)
|
198 |
|
199 |
+
# Directly use the outputs
|
200 |
+
main_report = report_result if report_result else "โ ๏ธ No Report Generated."
|
201 |
+
conclusion = conclusion_result if conclusion_result else "โ ๏ธ No Conclusion Generated."
|
202 |
|
203 |
st.markdown("### Analysis Report:")
|
204 |
st.markdown(main_report)
|
|
|
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)")
|
260 |
+
|