Spaces:
Sleeping
Sleeping
DrishtiSharma
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -163,23 +163,54 @@ if st.session_state.df is not None:
|
|
163 |
# UI: Tabs for Query Results and General Insights
|
164 |
tab1, tab2 = st.tabs(["π Query Insights + Viz", "π Full Data Viz"])
|
165 |
|
|
|
166 |
with tab1:
|
167 |
query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
with tab2:
|
170 |
st.subheader("π Comprehensive Data Visualizations")
|
171 |
-
|
172 |
fig1 = px.histogram(st.session_state.df, x="job_title", title="Job Title Frequency")
|
173 |
st.plotly_chart(fig1)
|
174 |
|
175 |
-
fig2 = px.bar(
|
176 |
-
|
|
|
|
|
|
|
177 |
st.plotly_chart(fig2)
|
178 |
|
179 |
temp_dir.cleanup()
|
180 |
else:
|
181 |
st.info("Please load a dataset to proceed.")
|
182 |
-
|
183 |
-
with st.sidebar:
|
184 |
-
st.header("π Reference:")
|
185 |
-
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)")
|
|
|
163 |
# UI: Tabs for Query Results and General Insights
|
164 |
tab1, tab2 = st.tabs(["π Query Insights + Viz", "π Full Data Viz"])
|
165 |
|
166 |
+
# Tab 1: Query Insights + Visualization
|
167 |
with tab1:
|
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 |
+
inputs = {"query": query}
|
172 |
+
result = crew.kickoff(inputs=inputs)
|
173 |
+
st.markdown("### Analysis Report:")
|
174 |
+
|
175 |
+
# Create visualization if the query is about salary
|
176 |
+
if "salary" in query.lower():
|
177 |
+
fig = px.box(st.session_state.df, x="job_title", y="salary_in_usd",
|
178 |
+
title="Salary Distribution by Job Title")
|
179 |
+
|
180 |
+
# Insert visualization after "5. Company Size"
|
181 |
+
insert_section = "5. Company Size"
|
182 |
+
if insert_section in result:
|
183 |
+
# Split the report at the "Company Size" section
|
184 |
+
parts = result.split(insert_section)
|
185 |
+
st.markdown(parts[0]) # Display everything before "Company Size"
|
186 |
+
st.markdown(f"## {insert_section}{parts[1].split('6.')[0]}") # Show the "Company Size" content
|
187 |
+
|
188 |
+
# Insert the visualization here
|
189 |
+
st.plotly_chart(fig, use_container_width=True)
|
190 |
+
|
191 |
+
# Continue with the rest of the report
|
192 |
+
st.markdown("## 6." + parts[1].split("6.")[1]) # Display everything after "Company Size"
|
193 |
+
else:
|
194 |
+
# If "Company Size" not found, show full report and plot at the end
|
195 |
+
st.markdown(result)
|
196 |
+
st.plotly_chart(fig, use_container_width=True)
|
197 |
+
else:
|
198 |
+
st.markdown(result)
|
199 |
+
|
200 |
+
# Tab 2: Full Data Visualization
|
201 |
with tab2:
|
202 |
st.subheader("π Comprehensive Data Visualizations")
|
203 |
+
|
204 |
fig1 = px.histogram(st.session_state.df, x="job_title", title="Job Title Frequency")
|
205 |
st.plotly_chart(fig1)
|
206 |
|
207 |
+
fig2 = px.bar(
|
208 |
+
st.session_state.df.groupby("experience_level")["salary_in_usd"].mean().reset_index(),
|
209 |
+
x="experience_level", y="salary_in_usd",
|
210 |
+
title="Average Salary by Experience Level"
|
211 |
+
)
|
212 |
st.plotly_chart(fig2)
|
213 |
|
214 |
temp_dir.cleanup()
|
215 |
else:
|
216 |
st.info("Please load a dataset to proceed.")
|
|
|
|
|
|
|
|