Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -172,39 +172,57 @@ if st.session_state.df is not None:
|
|
172 |
result = crew.kickoff(inputs=inputs)
|
173 |
st.markdown("### Analysis Report:")
|
174 |
|
175 |
-
#
|
|
|
|
|
|
|
176 |
if "salary" in query.lower():
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
st.
|
185 |
-
|
186 |
-
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
st.plotly_chart(fig, use_container_width=True)
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
else:
|
193 |
-
# Default behavior if the section isn't found
|
194 |
-
st.markdown(result)
|
195 |
-
st.plotly_chart(fig, use_container_width=True)
|
196 |
else:
|
197 |
st.markdown(result)
|
|
|
|
|
|
|
|
|
198 |
|
199 |
# Tab 2: Full Data Visualization
|
200 |
with tab2:
|
201 |
st.subheader("π Comprehensive Data Visualizations")
|
202 |
|
203 |
-
# Histogram of job titles
|
204 |
fig1 = px.histogram(st.session_state.df, x="job_title", title="Job Title Frequency")
|
205 |
st.plotly_chart(fig1)
|
206 |
|
207 |
-
# Bar chart of average salary by experience level
|
208 |
fig2 = px.bar(
|
209 |
st.session_state.df.groupby("experience_level")["salary_in_usd"].mean().reset_index(),
|
210 |
x="experience_level", y="salary_in_usd",
|
@@ -212,18 +230,15 @@ if st.session_state.df is not None:
|
|
212 |
)
|
213 |
st.plotly_chart(fig2)
|
214 |
|
215 |
-
# Salary by Employment Type
|
216 |
fig3 = px.box(st.session_state.df, x="employment_type", y="salary_in_usd",
|
217 |
title="Salary Distribution by Employment Type")
|
218 |
st.plotly_chart(fig3)
|
219 |
|
220 |
-
# Salary by Company Size (if available)
|
221 |
if "company_size" in st.session_state.df.columns:
|
222 |
fig4 = px.box(st.session_state.df, x="company_size", y="salary_in_usd",
|
223 |
title="Salary Distribution by Company Size")
|
224 |
st.plotly_chart(fig4)
|
225 |
|
226 |
-
# Salary by Region (if available)
|
227 |
if "region" in st.session_state.df.columns:
|
228 |
fig5 = px.box(st.session_state.df, x="region", y="salary_in_usd",
|
229 |
title="Salary Distribution by Region")
|
|
|
172 |
result = crew.kickoff(inputs=inputs)
|
173 |
st.markdown("### Analysis Report:")
|
174 |
|
175 |
+
# Collect all generated visualizations
|
176 |
+
visualizations = []
|
177 |
+
|
178 |
+
# Salary Visualization
|
179 |
if "salary" in query.lower():
|
180 |
+
fig_salary = px.box(st.session_state.df, x="job_title", y="salary_in_usd",
|
181 |
+
title="Salary Distribution by Job Title")
|
182 |
+
visualizations.append(fig_salary)
|
183 |
+
|
184 |
+
# Experience Level Visualization
|
185 |
+
if "experience" in query.lower():
|
186 |
+
fig_experience = px.bar(
|
187 |
+
st.session_state.df.groupby("experience_level")["salary_in_usd"].mean().reset_index(),
|
188 |
+
x="experience_level", y="salary_in_usd",
|
189 |
+
title="Average Salary by Experience Level"
|
190 |
+
)
|
191 |
+
visualizations.append(fig_experience)
|
192 |
+
|
193 |
+
# Employment Type Visualization
|
194 |
+
if "employment" in query.lower():
|
195 |
+
fig_employment = px.box(st.session_state.df, x="employment_type", y="salary_in_usd",
|
196 |
+
title="Salary Distribution by Employment Type")
|
197 |
+
visualizations.append(fig_employment)
|
198 |
+
|
199 |
+
# Insert "Visual Insights" before Conclusion
|
200 |
+
insert_section = "## Conclusion"
|
201 |
+
if insert_section in result and visualizations:
|
202 |
+
parts = result.split(insert_section)
|
203 |
+
st.markdown(parts[0]) # Content before Conclusion
|
204 |
+
|
205 |
+
# Insert Visual Insights Section
|
206 |
+
st.markdown("## π Visual Insights")
|
207 |
+
for fig in visualizations:
|
208 |
st.plotly_chart(fig, use_container_width=True)
|
209 |
|
210 |
+
# Continue with Conclusion
|
211 |
+
st.markdown(insert_section + parts[1])
|
|
|
|
|
|
|
|
|
212 |
else:
|
213 |
st.markdown(result)
|
214 |
+
if visualizations:
|
215 |
+
st.markdown("## π Visual Insights")
|
216 |
+
for fig in visualizations:
|
217 |
+
st.plotly_chart(fig, use_container_width=True)
|
218 |
|
219 |
# Tab 2: Full Data Visualization
|
220 |
with tab2:
|
221 |
st.subheader("π Comprehensive Data Visualizations")
|
222 |
|
|
|
223 |
fig1 = px.histogram(st.session_state.df, x="job_title", title="Job Title Frequency")
|
224 |
st.plotly_chart(fig1)
|
225 |
|
|
|
226 |
fig2 = px.bar(
|
227 |
st.session_state.df.groupby("experience_level")["salary_in_usd"].mean().reset_index(),
|
228 |
x="experience_level", y="salary_in_usd",
|
|
|
230 |
)
|
231 |
st.plotly_chart(fig2)
|
232 |
|
|
|
233 |
fig3 = px.box(st.session_state.df, x="employment_type", y="salary_in_usd",
|
234 |
title="Salary Distribution by Employment Type")
|
235 |
st.plotly_chart(fig3)
|
236 |
|
|
|
237 |
if "company_size" in st.session_state.df.columns:
|
238 |
fig4 = px.box(st.session_state.df, x="company_size", y="salary_in_usd",
|
239 |
title="Salary Distribution by Company Size")
|
240 |
st.plotly_chart(fig4)
|
241 |
|
|
|
242 |
if "region" in st.session_state.df.columns:
|
243 |
fig5 = px.box(st.session_state.df, x="region", y="salary_in_usd",
|
244 |
title="Salary Distribution by Region")
|