Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +26 -6
src/streamlit_app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
Enhanced Telecom Customer Segmentation Dashboard
|
| 3 |
===============================================
|
| 4 |
-
|
| 5 |
β
Interactive visual insights
|
| 6 |
β
Communication: Location, Intl calls, Frequency, Duration, Time (Morning/Noon/Night)
|
| 7 |
β
Internet: Download, Upload, Overall
|
|
@@ -363,15 +362,36 @@ def render_internet_insights(stats):
|
|
| 363 |
def render_sms_insights(stats):
|
| 364 |
st.subheader("π¬ SMS Insights")
|
| 365 |
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
with col1:
|
| 369 |
st.metric("Total Messages", f"{stats['total_sms']:,}")
|
| 370 |
with col2:
|
| 371 |
-
st.metric("Average per User", f"{stats['avg_sms_per_user']:.1f}")
|
| 372 |
-
with col3:
|
| 373 |
st.metric("SMS Users", f"{stats['sms_users']:,}",
|
| 374 |
-
f"{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
|
| 376 |
# Frequency distribution
|
| 377 |
freq_high = int(stats['sms_users'] * 0.25) # Estimate
|
|
@@ -381,7 +401,7 @@ def render_sms_insights(stats):
|
|
| 381 |
fig = px.bar(
|
| 382 |
x=['High Frequency', 'Medium Frequency', 'Low Frequency'],
|
| 383 |
y=[freq_high, freq_medium, freq_low],
|
| 384 |
-
title="SMS Frequency Distribution (
|
| 385 |
labels={'x': 'Frequency', 'y': 'Number of Users'},
|
| 386 |
color=['High', 'Medium', 'Low'],
|
| 387 |
color_discrete_sequence=['#E74C3C', '#F39C12', '#3498DB']
|
|
|
|
| 1 |
"""
|
| 2 |
Enhanced Telecom Customer Segmentation Dashboard
|
| 3 |
===============================================
|
|
|
|
| 4 |
β
Interactive visual insights
|
| 5 |
β
Communication: Location, Intl calls, Frequency, Duration, Time (Morning/Noon/Night)
|
| 6 |
β
Internet: Download, Upload, Overall
|
|
|
|
| 362 |
def render_sms_insights(stats):
|
| 363 |
st.subheader("π¬ SMS Insights")
|
| 364 |
|
| 365 |
+
# Calculate meaningful metrics
|
| 366 |
+
sms_adoption_rate = (stats['sms_users'] / stats['total_customers'] * 100)
|
| 367 |
+
avg_per_active = stats.get('avg_sms_per_active_user', 2.0) # Fallback if backend not updated
|
| 368 |
+
|
| 369 |
+
# Alert if SMS usage is very low
|
| 370 |
+
if sms_adoption_rate < 5:
|
| 371 |
+
st.warning(f"β οΈ **Low SMS Adoption:** Only {sms_adoption_rate:.1f}% of customers use SMS. Most likely prefer OTT messaging apps (WhatsApp, Telegram, etc.)")
|
| 372 |
+
|
| 373 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 374 |
|
| 375 |
with col1:
|
| 376 |
st.metric("Total Messages", f"{stats['total_sms']:,}")
|
| 377 |
with col2:
|
|
|
|
|
|
|
| 378 |
st.metric("SMS Users", f"{stats['sms_users']:,}",
|
| 379 |
+
f"{sms_adoption_rate:.1f}% adoption")
|
| 380 |
+
with col3:
|
| 381 |
+
st.metric("Avg (Active Users)", f"{avg_per_active:.1f} msgs",
|
| 382 |
+
help="Average messages among customers who actually use SMS")
|
| 383 |
+
with col4:
|
| 384 |
+
st.metric("Avg (All Users)", f"{stats['avg_sms_per_user']:.2f} msgs",
|
| 385 |
+
help="Average across all customers (includes 98%+ with 0 SMS)")
|
| 386 |
+
|
| 387 |
+
# Insight box
|
| 388 |
+
st.info(f"""
|
| 389 |
+
**π SMS Analysis:**
|
| 390 |
+
- **{stats['sms_users']:,}** customers sent SMS (only **{sms_adoption_rate:.1f}%** of total)
|
| 391 |
+
- Active SMS users average **{avg_per_active:.1f} messages** each
|
| 392 |
+
- **{stats['total_customers'] - stats['sms_users']:,}** customers (**{100-sms_adoption_rate:.1f}%**) sent **ZERO** SMS
|
| 393 |
+
- This suggests heavy reliance on OTT messaging apps (WhatsApp, Telegram, etc.)
|
| 394 |
+
""")
|
| 395 |
|
| 396 |
# Frequency distribution
|
| 397 |
freq_high = int(stats['sms_users'] * 0.25) # Estimate
|
|
|
|
| 401 |
fig = px.bar(
|
| 402 |
x=['High Frequency', 'Medium Frequency', 'Low Frequency'],
|
| 403 |
y=[freq_high, freq_medium, freq_low],
|
| 404 |
+
title="SMS Frequency Distribution (Among Active Users Only)",
|
| 405 |
labels={'x': 'Frequency', 'y': 'Number of Users'},
|
| 406 |
color=['High', 'Medium', 'Low'],
|
| 407 |
color_discrete_sequence=['#E74C3C', '#F39C12', '#3498DB']
|