Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1268,6 +1268,11 @@ import plotly.graph_objects as go
|
|
| 1268 |
import numpy as np
|
| 1269 |
import pandas as pd
|
| 1270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1271 |
# =================== OBJECTIVE 6 - Predictive Dashboard & Early Warning Signals ===================
|
| 1272 |
st.markdown("<h3 class='section-title'>OBJECTIVE 6 — Predictive Dashboard & Early Warning Signals</h3>", unsafe_allow_html=True)
|
| 1273 |
|
|
@@ -1476,7 +1481,8 @@ def predict_creators(df):
|
|
| 1476 |
except:
|
| 1477 |
continue
|
| 1478 |
df_res = pd.DataFrame(results)
|
| 1479 |
-
|
|
|
|
| 1480 |
|
| 1481 |
# ——————— 3. Issues: ONLY Coverage=100% & Trend Slope > 0 → Avg/Month ———————
|
| 1482 |
def predict_issues(df):
|
|
@@ -1541,7 +1547,7 @@ df_issue = predict_issues(df_filtered)
|
|
| 1541 |
|
| 1542 |
# 🎯 PANEL 1: Creators (FILTERED: Coverage < 90% & Slope < 0) — Non-Positive Only
|
| 1543 |
st.markdown("<div class='predictive-panel'>", unsafe_allow_html=True)
|
| 1544 |
-
st.markdown("<div class='predictive-header'>1. Which Reporters Are Predicted to Have No Future Inspections? (
|
| 1545 |
if not df_creator.empty:
|
| 1546 |
cols = ['Creator', 'Avg Reports/Month', 'Coverage (%)', 'Trend Slope', 'Trend', 'Reason']
|
| 1547 |
|
|
@@ -1575,10 +1581,55 @@ if not df_creator.empty:
|
|
| 1575 |
# )
|
| 1576 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 1577 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1578 |
|
| 1579 |
|
| 1580 |
# =================== WHITEBOARD STYLE CHART FOR PANEL 3 ===================
|
| 1581 |
-
st.markdown("<h4 style='text-align: center; color: #2c3e50;'>
|
| 1582 |
|
| 1583 |
# Buat chart scatter dengan gaya whiteboard
|
| 1584 |
if not df_issue.empty:
|
|
@@ -1682,7 +1733,6 @@ if not df_issue.empty:
|
|
| 1682 |
st.markdown(insight_text, unsafe_allow_html=True)
|
| 1683 |
else:
|
| 1684 |
st.info("No data available for non-positive issues with 100% coverage and positive trend.")
|
| 1685 |
-
|
| 1686 |
# =================== 6. ✅ AI INSIGHT ENGINE (BARU - BERDASARKAN DATA & RATIO) ===================
|
| 1687 |
|
| 1688 |
st.markdown("<h3 class='section-title'>OBJECTIVE 7 - Insight and Recommendation</h3>", unsafe_allow_html=True)
|
|
|
|
| 1268 |
import numpy as np
|
| 1269 |
import pandas as pd
|
| 1270 |
|
| 1271 |
+
import streamlit as st
|
| 1272 |
+
import plotly.graph_objects as go
|
| 1273 |
+
import numpy as np
|
| 1274 |
+
import pandas as pd
|
| 1275 |
+
|
| 1276 |
# =================== OBJECTIVE 6 - Predictive Dashboard & Early Warning Signals ===================
|
| 1277 |
st.markdown("<h3 class='section-title'>OBJECTIVE 6 — Predictive Dashboard & Early Warning Signals</h3>", unsafe_allow_html=True)
|
| 1278 |
|
|
|
|
| 1481 |
except:
|
| 1482 |
continue
|
| 1483 |
df_res = pd.DataFrame(results)
|
| 1484 |
+
# ✅ Ambil 10 creator dengan slope paling negatif (paling turun)
|
| 1485 |
+
return df_res.sort_values('Trend Slope', ascending=True).head(10) if not df_res.empty else df_res
|
| 1486 |
|
| 1487 |
# ——————— 3. Issues: ONLY Coverage=100% & Trend Slope > 0 → Avg/Month ———————
|
| 1488 |
def predict_issues(df):
|
|
|
|
| 1547 |
|
| 1548 |
# 🎯 PANEL 1: Creators (FILTERED: Coverage < 90% & Slope < 0) — Non-Positive Only
|
| 1549 |
st.markdown("<div class='predictive-panel'>", unsafe_allow_html=True)
|
| 1550 |
+
st.markdown("<div class='predictive-header'>1. Which Reporters Are Predicted to Have No Future Inspections? (Top 10 Most Declining)</div>", unsafe_allow_html=True)
|
| 1551 |
if not df_creator.empty:
|
| 1552 |
cols = ['Creator', 'Avg Reports/Month', 'Coverage (%)', 'Trend Slope', 'Trend', 'Reason']
|
| 1553 |
|
|
|
|
| 1581 |
# )
|
| 1582 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 1583 |
|
| 1584 |
+
# 🎯 PANEL 3: Issues (FILTERED: Coverage=100% & Rising) — Hanya Non-Positive
|
| 1585 |
+
st.markdown("<div class='predictive-panel'>", unsafe_allow_html=True)
|
| 1586 |
+
st.markdown(
|
| 1587 |
+
"<div class='predictive-header'>"
|
| 1588 |
+
"3. Which Issue Categories Are Likely to Appear in the Next 3 Months (Non-Positive Only)"
|
| 1589 |
+
"<span style='font-size:0.75em; font-weight:400; color:#003DA5;'>"
|
| 1590 |
+
" (* Categorization uses NLP — Natural Language Processing from random text)"
|
| 1591 |
+
"</span>"
|
| 1592 |
+
"</div>",
|
| 1593 |
+
unsafe_allow_html=True
|
| 1594 |
+
)
|
| 1595 |
+
|
| 1596 |
+
if not df_issue.empty:
|
| 1597 |
+
cols = ['Category', 'Avg/Month', 'Coverage (%)', 'Trend Slope', 'Status', 'Trend']
|
| 1598 |
+
|
| 1599 |
+
# 🔵 Rename ONLY for display
|
| 1600 |
+
df_display = df_issue[cols].rename(columns={
|
| 1601 |
+
"Status": "Status Issue for Next Month"
|
| 1602 |
+
})
|
| 1603 |
+
|
| 1604 |
+
html = df_display.to_html(escape=False, index=False, table_id="tbl-issues")
|
| 1605 |
+
st.markdown(f"<div class='predictive-table-wrapper'>{html}</div>", unsafe_allow_html=True)
|
| 1606 |
+
|
| 1607 |
+
# st.markdown(
|
| 1608 |
+
# "<div class='predictive-note'>"
|
| 1609 |
+
# "<strong>Filtered:</strong> Reported every month (100% coverage) with increasing trend. "
|
| 1610 |
+
# "<strong>Avg/Month</strong> = total ÷ months. "
|
| 1611 |
+
# "<span class='trend-rising'>High-Risk Rising</span> = slope > 0.2."
|
| 1612 |
+
# "</div>",
|
| 1613 |
+
# unsafe_allow_html=True
|
| 1614 |
+
# )
|
| 1615 |
+
|
| 1616 |
+
# else:
|
| 1617 |
+
# st.markdown(
|
| 1618 |
+
# "<div class='predictive-table-wrapper'>"
|
| 1619 |
+
# "<p style='text-align:center; color:#c62828; padding:24px; font-weight:500;'>"
|
| 1620 |
+
# "⚠️ No rising categories with 100% monthly coverage."
|
| 1621 |
+
# "</p>"
|
| 1622 |
+
# "<p style='text-align:center; color:#666; font-size:0.9em;'>"
|
| 1623 |
+
# "Consider relaxing coverage filter if data is sparse."
|
| 1624 |
+
# "</p></div>",
|
| 1625 |
+
# unsafe_allow_html=True
|
| 1626 |
+
# )
|
| 1627 |
+
|
| 1628 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 1629 |
|
| 1630 |
|
| 1631 |
# =================== WHITEBOARD STYLE CHART FOR PANEL 3 ===================
|
| 1632 |
+
st.markdown("<h4 style='text-align: center; color: #2c3e50;'>Whiteboard Insight: Trend vs Frequency</h4>", unsafe_allow_html=True)
|
| 1633 |
|
| 1634 |
# Buat chart scatter dengan gaya whiteboard
|
| 1635 |
if not df_issue.empty:
|
|
|
|
| 1733 |
st.markdown(insight_text, unsafe_allow_html=True)
|
| 1734 |
else:
|
| 1735 |
st.info("No data available for non-positive issues with 100% coverage and positive trend.")
|
|
|
|
| 1736 |
# =================== 6. ✅ AI INSIGHT ENGINE (BARU - BERDASARKAN DATA & RATIO) ===================
|
| 1737 |
|
| 1738 |
st.markdown("<h3 class='section-title'>OBJECTIVE 7 - Insight and Recommendation</h3>", unsafe_allow_html=True)
|