Spaces:
Sleeping
Sleeping
DrishtiSharma
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -111,6 +111,7 @@ if st.session_state.df is not None:
|
|
111 |
"""Validate the SQL query syntax and structure before execution."""
|
112 |
return QuerySQLCheckerTool(db=db, llm=llm).invoke({"query": sql_query})
|
113 |
|
|
|
114 |
sql_dev = Agent(
|
115 |
role="Senior Database Developer",
|
116 |
goal="Extract data using optimized SQL queries.",
|
@@ -119,6 +120,7 @@ if st.session_state.df is not None:
|
|
119 |
tools=[list_tables, tables_schema, execute_sql, check_sql],
|
120 |
)
|
121 |
|
|
|
122 |
data_analyst = Agent(
|
123 |
role="Senior Data Analyst",
|
124 |
goal="Analyze the data and produce insights.",
|
@@ -126,13 +128,23 @@ if st.session_state.df is not None:
|
|
126 |
llm=llm,
|
127 |
)
|
128 |
|
|
|
129 |
report_writer = Agent(
|
130 |
role="Technical Report Writer",
|
131 |
-
goal="
|
132 |
-
backstory="An expert in
|
133 |
llm=llm,
|
134 |
)
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
extract_data = Task(
|
137 |
description="Extract data based on the query: {query}.",
|
138 |
expected_output="Database results matching the query.",
|
@@ -141,25 +153,40 @@ if st.session_state.df is not None:
|
|
141 |
|
142 |
analyze_data = Task(
|
143 |
description="Analyze the extracted data for query: {query}.",
|
144 |
-
expected_output="Provide
|
145 |
agent=data_analyst,
|
146 |
context=[extract_data],
|
147 |
)
|
148 |
|
149 |
write_report = Task(
|
150 |
-
description="
|
151 |
-
expected_output="Markdown report excluding
|
152 |
agent=report_writer,
|
153 |
context=[analyze_data],
|
154 |
)
|
155 |
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
agents=[sql_dev, data_analyst, report_writer],
|
158 |
tasks=[extract_data, analyze_data, write_report],
|
159 |
process=Process.sequential,
|
160 |
verbose=True,
|
161 |
)
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
# Tabs for Query Results and General Insights
|
164 |
tab1, tab2 = st.tabs(["π Query Insights + Viz", "π Full Data Viz"])
|
165 |
|
@@ -168,15 +195,13 @@ if st.session_state.df is not None:
|
|
168 |
query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
|
169 |
if st.button("Submit Query"):
|
170 |
with st.spinner("Processing query..."):
|
171 |
-
# Step 1: Generate the
|
172 |
-
|
173 |
-
|
174 |
-
report_result = crew.kickoff(inputs=inputs)
|
175 |
|
176 |
# Step 2: Generate ONLY the Conclusion
|
177 |
-
|
178 |
-
|
179 |
-
conclusion_result = crew.kickoff(inputs=conclusion_inputs)
|
180 |
|
181 |
st.markdown("### Analysis Report:")
|
182 |
|
@@ -198,7 +223,7 @@ if st.session_state.df is not None:
|
|
198 |
title="Salary Distribution by Employment Type")
|
199 |
visualizations.append(fig_employment)
|
200 |
|
201 |
-
# Step 4: Display
|
202 |
st.markdown(report_result)
|
203 |
|
204 |
# Step 5: Insert Visual Insights
|
@@ -232,6 +257,7 @@ if st.session_state.df is not None:
|
|
232 |
else:
|
233 |
st.info("Please load a dataset to proceed.")
|
234 |
|
|
|
235 |
# Sidebar Reference
|
236 |
with st.sidebar:
|
237 |
st.header("π Reference:")
|
|
|
111 |
"""Validate the SQL query syntax and structure before execution."""
|
112 |
return QuerySQLCheckerTool(db=db, llm=llm).invoke({"query": sql_query})
|
113 |
|
114 |
+
# Agent for SQL data extraction
|
115 |
sql_dev = Agent(
|
116 |
role="Senior Database Developer",
|
117 |
goal="Extract data using optimized SQL queries.",
|
|
|
120 |
tools=[list_tables, tables_schema, execute_sql, check_sql],
|
121 |
)
|
122 |
|
123 |
+
# Agent for data analysis
|
124 |
data_analyst = Agent(
|
125 |
role="Senior Data Analyst",
|
126 |
goal="Analyze the data and produce insights.",
|
|
|
128 |
llm=llm,
|
129 |
)
|
130 |
|
131 |
+
# Agent for generating the main report (without Conclusion)
|
132 |
report_writer = Agent(
|
133 |
role="Technical Report Writer",
|
134 |
+
goal="Write a clear, structured report containing ONLY Key Insights and Analysis. NO Introduction, Summary, or Conclusion.",
|
135 |
+
backstory="An expert in crafting data-driven reports with clear insights.",
|
136 |
llm=llm,
|
137 |
)
|
138 |
|
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 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.",
|
|
|
153 |
|
154 |
analyze_data = Task(
|
155 |
description="Analyze the extracted data for query: {query}.",
|
156 |
+
expected_output="Provide ONLY Key Insights and Analysis. Exclude Introduction and Conclusion.",
|
157 |
agent=data_analyst,
|
158 |
context=[extract_data],
|
159 |
)
|
160 |
|
161 |
write_report = Task(
|
162 |
+
description="Write the report with ONLY Key Insights and Analysis. DO NOT include Introduction or Conclusion.",
|
163 |
+
expected_output="Markdown report excluding Introduction and Conclusion.",
|
164 |
agent=report_writer,
|
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 with separate tasks for report and conclusion
|
176 |
+
crew_report = Crew(
|
177 |
agents=[sql_dev, data_analyst, report_writer],
|
178 |
tasks=[extract_data, analyze_data, write_report],
|
179 |
process=Process.sequential,
|
180 |
verbose=True,
|
181 |
)
|
182 |
|
183 |
+
crew_conclusion = Crew(
|
184 |
+
agents=[data_analyst, conclusion_writer],
|
185 |
+
tasks=[write_conclusion],
|
186 |
+
process=Process.sequential,
|
187 |
+
verbose=True,
|
188 |
+
)
|
189 |
+
|
190 |
# Tabs for Query Results and General Insights
|
191 |
tab1, tab2 = st.tabs(["π Query Insights + Viz", "π Full Data Viz"])
|
192 |
|
|
|
195 |
query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
|
196 |
if st.button("Submit Query"):
|
197 |
with st.spinner("Processing query..."):
|
198 |
+
# Step 1: Generate the main report (without Conclusion)
|
199 |
+
report_inputs = {"query": query}
|
200 |
+
report_result = crew_report.kickoff(inputs=report_inputs)
|
|
|
201 |
|
202 |
# Step 2: Generate ONLY the Conclusion
|
203 |
+
conclusion_inputs = {"query": query}
|
204 |
+
conclusion_result = crew_conclusion.kickoff(inputs=conclusion_inputs)
|
|
|
205 |
|
206 |
st.markdown("### Analysis Report:")
|
207 |
|
|
|
223 |
title="Salary Distribution by Employment Type")
|
224 |
visualizations.append(fig_employment)
|
225 |
|
226 |
+
# Step 4: Display the main report
|
227 |
st.markdown(report_result)
|
228 |
|
229 |
# Step 5: Insert Visual Insights
|
|
|
257 |
else:
|
258 |
st.info("Please load a dataset to proceed.")
|
259 |
|
260 |
+
|
261 |
# Sidebar Reference
|
262 |
with st.sidebar:
|
263 |
st.header("π Reference:")
|