Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -200,7 +200,7 @@ elif tabs == 'Reports':
|
|
| 200 |
col1, col2 = st.columns([1, 1])
|
| 201 |
|
| 202 |
with col1:
|
| 203 |
-
if
|
| 204 |
try:
|
| 205 |
fig_gender = px.histogram(filtered_df, x="Gender", title="Gender Distribution")
|
| 206 |
fig_gender.update_layout(height=400, width=500)
|
|
@@ -208,9 +208,9 @@ elif tabs == 'Reports':
|
|
| 208 |
except Exception as e:
|
| 209 |
st.write(f"Error generating Gender visualization: {e}")
|
| 210 |
else:
|
| 211 |
-
st.write("Not enough data
|
| 212 |
|
| 213 |
-
if
|
| 214 |
try:
|
| 215 |
fig_youth = px.histogram(filtered_df, x="Youth", title="Youth Participation")
|
| 216 |
fig_youth.update_layout(height=400, width=500)
|
|
@@ -218,10 +218,10 @@ elif tabs == 'Reports':
|
|
| 218 |
except Exception as e:
|
| 219 |
st.write(f"Error generating Youth visualization: {e}")
|
| 220 |
else:
|
| 221 |
-
st.write("Not enough data
|
| 222 |
|
| 223 |
with col2:
|
| 224 |
-
if
|
| 225 |
try:
|
| 226 |
fig_category = px.histogram(filtered_df, x="Intervention_Category", title="Intervention Category Distribution")
|
| 227 |
fig_category.update_layout(height=400, width=500)
|
|
@@ -229,9 +229,9 @@ elif tabs == 'Reports':
|
|
| 229 |
except Exception as e:
|
| 230 |
st.write(f"Error generating Category visualization: {e}")
|
| 231 |
else:
|
| 232 |
-
st.write("Not enough data
|
| 233 |
|
| 234 |
-
if
|
| 235 |
try:
|
| 236 |
fig_intervention = px.histogram(filtered_df, x="Intervention", title="Intervention Type Distribution")
|
| 237 |
fig_intervention.update_layout(height=400, width=500)
|
|
@@ -239,18 +239,18 @@ elif tabs == 'Reports':
|
|
| 239 |
except Exception as e:
|
| 240 |
st.write(f"Error generating Intervention visualization: {e}")
|
| 241 |
else:
|
| 242 |
-
st.write("Not enough data to display Intervention Distribution (empty or
|
| 243 |
|
| 244 |
|
| 245 |
with st.spinner("Generating Report, Please Wait...."):
|
| 246 |
try:
|
|
|
|
| 247 |
prompt = f"""
|
| 248 |
You are an expert business analyst. Analyze the following data and generate a comprehensive and insightful business report,
|
| 249 |
including appropriate key performance indicators and recommendations.
|
| 250 |
Data: dataset:{str(filtered_df.to_json(orient='records'))},
|
| 251 |
kpi:{str(calculate_kpis(filtered_df))}, dataset profile:{str(get_pandas_profile(filtered_df))}
|
| 252 |
"""
|
| 253 |
-
|
| 254 |
response = model.generate_content(prompt)
|
| 255 |
report = response.text
|
| 256 |
st.markdown(report)
|
|
@@ -268,4 +268,6 @@ elif tabs == 'Reports':
|
|
| 268 |
|
| 269 |
else:
|
| 270 |
st.write("Click 'Apply Filters' to see the filtered data.")
|
| 271 |
-
|
|
|
|
|
|
|
|
|
| 200 |
col1, col2 = st.columns([1, 1])
|
| 201 |
|
| 202 |
with col1:
|
| 203 |
+
if 'Gender' in filtered_df.columns and filtered_df['Gender'].nunique() > 1 and pd.api.types.is_categorical_dtype(filtered_df['Gender']):
|
| 204 |
try:
|
| 205 |
fig_gender = px.histogram(filtered_df, x="Gender", title="Gender Distribution")
|
| 206 |
fig_gender.update_layout(height=400, width=500)
|
|
|
|
| 208 |
except Exception as e:
|
| 209 |
st.write(f"Error generating Gender visualization: {e}")
|
| 210 |
else:
|
| 211 |
+
st.write("Not enough data or incorrect data type for Gender Distribution (empty, single value, or not categorical).")
|
| 212 |
|
| 213 |
+
if 'Youth' in filtered_df.columns and filtered_df['Youth'].nunique() > 1 and pd.api.types.is_categorical_dtype(filtered_df['Youth']):
|
| 214 |
try:
|
| 215 |
fig_youth = px.histogram(filtered_df, x="Youth", title="Youth Participation")
|
| 216 |
fig_youth.update_layout(height=400, width=500)
|
|
|
|
| 218 |
except Exception as e:
|
| 219 |
st.write(f"Error generating Youth visualization: {e}")
|
| 220 |
else:
|
| 221 |
+
st.write("Not enough data or incorrect data type for Youth Distribution (empty, single value, or not categorical).")
|
| 222 |
|
| 223 |
with col2:
|
| 224 |
+
if 'Intervention_Category' in filtered_df.columns and filtered_df['Intervention_Category'].nunique() > 1 and pd.api.types.is_categorical_dtype(filtered_df['Intervention_Category']):
|
| 225 |
try:
|
| 226 |
fig_category = px.histogram(filtered_df, x="Intervention_Category", title="Intervention Category Distribution")
|
| 227 |
fig_category.update_layout(height=400, width=500)
|
|
|
|
| 229 |
except Exception as e:
|
| 230 |
st.write(f"Error generating Category visualization: {e}")
|
| 231 |
else:
|
| 232 |
+
st.write("Not enough data or incorrect data type for Category Distribution (empty, single value, or not categorical).")
|
| 233 |
|
| 234 |
+
if 'Intervention' in filtered_df.columns and filtered_df['Intervention'].nunique() > 1 and pd.api.types.is_categorical_dtype(filtered_df['Intervention']):
|
| 235 |
try:
|
| 236 |
fig_intervention = px.histogram(filtered_df, x="Intervention", title="Intervention Type Distribution")
|
| 237 |
fig_intervention.update_layout(height=400, width=500)
|
|
|
|
| 239 |
except Exception as e:
|
| 240 |
st.write(f"Error generating Intervention visualization: {e}")
|
| 241 |
else:
|
| 242 |
+
st.write("Not enough data to display Intervention Distribution (empty, single value, or not categorical).")
|
| 243 |
|
| 244 |
|
| 245 |
with st.spinner("Generating Report, Please Wait...."):
|
| 246 |
try:
|
| 247 |
+
|
| 248 |
prompt = f"""
|
| 249 |
You are an expert business analyst. Analyze the following data and generate a comprehensive and insightful business report,
|
| 250 |
including appropriate key performance indicators and recommendations.
|
| 251 |
Data: dataset:{str(filtered_df.to_json(orient='records'))},
|
| 252 |
kpi:{str(calculate_kpis(filtered_df))}, dataset profile:{str(get_pandas_profile(filtered_df))}
|
| 253 |
"""
|
|
|
|
| 254 |
response = model.generate_content(prompt)
|
| 255 |
report = response.text
|
| 256 |
st.markdown(report)
|
|
|
|
| 268 |
|
| 269 |
else:
|
| 270 |
st.write("Click 'Apply Filters' to see the filtered data.")
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
|