SHELLAPANDIANGANHUNGING commited on
Commit
de03bfb
·
verified ·
1 Parent(s): 39470a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -1122,7 +1122,7 @@ try:
1122
  # ================================
1123
  # 12. DISPLAY TABLE
1124
  # ================================
1125
- st.subheader("Operator Hazard Summary Table (8 Weeks Observed)")
1126
  table_display = (
1127
  risk_matrix[[
1128
  "Operator Name",
@@ -1546,7 +1546,7 @@ else:
1546
  for insight in ob_insights:
1547
  st.markdown(f"""
1548
  <div class="ai-insight-box">
1549
- <div class="ai-insight-title">Hazard Summary</div>
1550
  <p>{insight}</p>
1551
  </div>
1552
  """, unsafe_allow_html=True)
@@ -1573,7 +1573,7 @@ else:
1573
  for insight in coal_insights:
1574
  st.markdown(f"""
1575
  <div class="ai-insight-box">
1576
- <div class="ai-insight-title">Hazard Summary</div>
1577
  <p>{insight}</p>
1578
  </div>
1579
  """, unsafe_allow_html=True)
@@ -1657,9 +1657,6 @@ else:
1657
  except Exception as e:
1658
  st.error(f"Error in Top 10 Operator analysis: {str(e)}")
1659
  st.exception(e) # optionally show full traceback during dev
1660
-
1661
-
1662
-
1663
  # =================== OBJECTIVE 6: Automated Insights & AI Recommendations =====================
1664
  st.subheader("OBJECTIVE 6: Instant Insights & Recommendations")
1665
 
@@ -1685,7 +1682,7 @@ with col_insights:
1685
 
1686
  # 2. High-Speed Fatigue Analysis (Environmental Risk)
1687
  if col_speed and col_speed in df.columns:
1688
- high_speed_threshold = df[col_speed].quantile(0.75) if not df[col_speed].dropna().empty else 0
1689
  high_speed_fatigue = df[df[col_speed] >= high_speed_threshold] if high_speed_threshold > 0 else pd.DataFrame()
1690
  high_speed_pct = (len(high_speed_fatigue) / len(df)) * 100 if len(df) > 0 else 0
1691
 
@@ -1813,6 +1810,18 @@ with col_recs:
1813
  })
1814
 
1815
  for rec in ai_recs:
 
 
 
 
 
 
 
 
 
 
 
 
1816
  st.markdown(f"""
1817
  <div style="
1818
  background: #f8f9fa;
@@ -1841,10 +1850,10 @@ with col_recs:
1841
  <strong>Action:</strong> {rec['recommendation']}
1842
  </div>
1843
  <div style="font-size: 12px; padding: 8px; background: #e9ecef; border-radius: 5px; margin-top: 5px;">
1844
- <strong>Data Point:</strong> {rec['data_point']}
1845
  </div>
1846
  <div style="font-size: 12px; padding: 8px; background: #f1f1f1; border-radius: 5px; margin-top: 5px;">
1847
- <strong>AI Reasoning:</strong> {rec['reason']}
1848
  </div>
1849
  </div>
1850
  """, unsafe_allow_html=True)
 
1122
  # ================================
1123
  # 12. DISPLAY TABLE
1124
  # ================================
1125
+ st.subheader("Operator Risk Summary Table (8 Weeks Observed)")
1126
  table_display = (
1127
  risk_matrix[[
1128
  "Operator Name",
 
1546
  for insight in ob_insights:
1547
  st.markdown(f"""
1548
  <div class="ai-insight-box">
1549
+ <div class="ai-insight-title">Risk Summary</div>
1550
  <p>{insight}</p>
1551
  </div>
1552
  """, unsafe_allow_html=True)
 
1573
  for insight in coal_insights:
1574
  st.markdown(f"""
1575
  <div class="ai-insight-box">
1576
+ <div class="ai-insight-title">Risk Summary</div>
1577
  <p>{insight}</p>
1578
  </div>
1579
  """, unsafe_allow_html=True)
 
1657
  except Exception as e:
1658
  st.error(f"Error in Top 10 Operator analysis: {str(e)}")
1659
  st.exception(e) # optionally show full traceback during dev
 
 
 
1660
  # =================== OBJECTIVE 6: Automated Insights & AI Recommendations =====================
1661
  st.subheader("OBJECTIVE 6: Instant Insights & Recommendations")
1662
 
 
1682
 
1683
  # 2. High-Speed Fatigue Analysis (Environmental Risk)
1684
  if col_speed and col_speed in df.columns:
1685
+ high_speed_threshold = 20
1686
  high_speed_fatigue = df[df[col_speed] >= high_speed_threshold] if high_speed_threshold > 0 else pd.DataFrame()
1687
  high_speed_pct = (len(high_speed_fatigue) / len(df)) * 100 if len(df) > 0 else 0
1688
 
 
1810
  })
1811
 
1812
  for rec in ai_recs:
1813
+ # Ambil data_point dan ganti teks persentase di dalamnya menjadi warna merah
1814
+ data_point_text = rec['data_point']
1815
+ # Ganti pola persentase (X.X%) dengan span warna merah
1816
+ import re
1817
+ # Cari pola seperti "1.6%", "21.2%", dll.
1818
+ data_point_colored = re.sub(r'(\d+\.?\d*%)', r'<span style="color: red;">\1</span>', data_point_text)
1819
+
1820
+ # Ambil reason dan lakukan hal yang sama
1821
+ reason_text = rec['reason']
1822
+ reason_colored = re.sub(r'(\d+\.?\d*%)', r'<span style="color: red;">\1</span>', reason_text)
1823
+
1824
+ # Tampilkan rekomendasi dengan teks persentase berwarna merah
1825
  st.markdown(f"""
1826
  <div style="
1827
  background: #f8f9fa;
 
1850
  <strong>Action:</strong> {rec['recommendation']}
1851
  </div>
1852
  <div style="font-size: 12px; padding: 8px; background: #e9ecef; border-radius: 5px; margin-top: 5px;">
1853
+ <strong>Data Point:</strong> {data_point_colored}
1854
  </div>
1855
  <div style="font-size: 12px; padding: 8px; background: #f1f1f1; border-radius: 5px; margin-top: 5px;">
1856
+ <strong>AI Reasoning:</strong> {reason_colored}
1857
  </div>
1858
  </div>
1859
  """, unsafe_allow_html=True)