Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1127,88 +1127,6 @@ st.markdown(f"""
|
|
| 1127 |
</div>
|
| 1128 |
</div>
|
| 1129 |
""", unsafe_allow_html=True)
|
| 1130 |
-
# =============== INSIGHT 3 ===============
|
| 1131 |
-
if alarm_data.empty:
|
| 1132 |
-
insight_text = "β’ No data available for analysis."
|
| 1133 |
-
else:
|
| 1134 |
-
# Insight tetap sama
|
| 1135 |
-
alarm_hours = alarm_data['hour']
|
| 1136 |
-
|
| 1137 |
-
def hour_to_band(h):
|
| 1138 |
-
if 0 <= h < 6: return "00:00β06:00 (Night)"
|
| 1139 |
-
if 6 <= h < 12: return "06:00β12:00 (Morning)"
|
| 1140 |
-
if 12 <= h < 18: return "12:00β18:00 (Afternoon)"
|
| 1141 |
-
return "18:00β00:00 (Evening)"
|
| 1142 |
-
|
| 1143 |
-
alarm_hours_df = pd.DataFrame({'hour': alarm_hours})
|
| 1144 |
-
alarm_hours_df['band'] = alarm_hours_df['hour'].apply(hour_to_band)
|
| 1145 |
-
band_counts = alarm_hours_df['band'].value_counts().sort_index()
|
| 1146 |
-
|
| 1147 |
-
top_bands = band_counts.nlargest(2)
|
| 1148 |
-
dominant_band = top_bands.index[0] if len(top_bands) > 0 else "N/A"
|
| 1149 |
-
second_dominant_band = top_bands.index[1] if len(top_bands) > 1 else "N/A"
|
| 1150 |
-
|
| 1151 |
-
dominant_pct = (top_bands.iloc[0] / band_counts.sum() * 100) if len(top_bands) > 0 else 0
|
| 1152 |
-
second_pct = (top_bands.iloc[1] / band_counts.sum() * 100) if len(top_bands) > 1 else 0
|
| 1153 |
-
|
| 1154 |
-
# Hitung jumlah masing-masing jenis alarm
|
| 1155 |
-
normal_alarms = alarm_data[alarm_data['Alarm Status'] == 'No Alarm'].shape[0]
|
| 1156 |
-
red_alarms = alarm_data[alarm_data['Alarm Status'].str.contains('Red', na=False)].shape[0]
|
| 1157 |
-
amber_alarms = alarm_data[alarm_data['Alarm Status'].str.contains('Amber', na=False)].shape[0]
|
| 1158 |
-
|
| 1159 |
-
# Insight Spesifik Per Position dan Shift
|
| 1160 |
-
insight_lines = [
|
| 1161 |
-
f"β’ Total alarms: Normal={normal_alarms}, Amber={amber_alarms}, Red={red_alarms}",
|
| 1162 |
-
f"β’ Dominant period: {dominant_band} ({dominant_pct:.1f}%), Second: {second_dominant_band} ({second_pct:.1f}%)"
|
| 1163 |
-
]
|
| 1164 |
-
|
| 1165 |
-
# Front Tyres (Position 1 & 2)
|
| 1166 |
-
front_data = alarm_data[alarm_data['Position'].isin([1, 2])]
|
| 1167 |
-
front_pagi = front_data[front_data['hour'].between(6, 17, inclusive='both')]
|
| 1168 |
-
front_sore = front_data[~front_data['hour'].between(6, 17, inclusive='both')]
|
| 1169 |
-
|
| 1170 |
-
if not front_pagi.empty:
|
| 1171 |
-
front_pagi_total = front_pagi.groupby('hour').size()
|
| 1172 |
-
if not front_pagi_total.empty:
|
| 1173 |
-
dominant_hour_front_pagi = front_pagi_total.idxmax()
|
| 1174 |
-
dominant_count_front_pagi = front_pagi_total.max()
|
| 1175 |
-
insight_lines.append(f"β’ Front Shift 1 (06:00β18:00): Peak at {dominant_hour_front_pagi:02d}:00 ({dominant_count_front_pagi} alarms)")
|
| 1176 |
-
if not front_sore.empty:
|
| 1177 |
-
front_sore_total = front_sore.groupby('hour').size()
|
| 1178 |
-
if not front_sore_total.empty:
|
| 1179 |
-
dominant_hour_front_sore = front_sore_total.idxmax()
|
| 1180 |
-
dominant_count_front_sore = front_sore_total.max()
|
| 1181 |
-
insight_lines.append(f"β’ Front Shift 2 (18:00β06:00): Peak at {dominant_hour_front_sore:02d}:00 ({dominant_count_front_sore} alarms)")
|
| 1182 |
-
|
| 1183 |
-
# Rear Tyres (Position 3 & 4)
|
| 1184 |
-
rear_data = alarm_data[alarm_data['Position'].isin([3, 4])]
|
| 1185 |
-
rear_pagi = rear_data[rear_data['hour'].between(6, 17, inclusive='both')]
|
| 1186 |
-
rear_sore = rear_data[~rear_data['hour'].between(6, 17, inclusive='both')]
|
| 1187 |
-
|
| 1188 |
-
if not rear_pagi.empty:
|
| 1189 |
-
rear_pagi_total = rear_pagi.groupby('hour').size()
|
| 1190 |
-
if not rear_pagi_total.empty:
|
| 1191 |
-
dominant_hour_rear_pagi = rear_pagi_total.idxmax()
|
| 1192 |
-
dominant_count_rear_pagi = rear_pagi_total.max()
|
| 1193 |
-
insight_lines.append(f"β’ Rear Shift 1 (06:00β18:00): Peak at {dominant_hour_rear_pagi:02d}:00 ({dominant_count_rear_pagi} alarms)")
|
| 1194 |
-
if not rear_sore.empty:
|
| 1195 |
-
rear_sore_total = rear_sore.groupby('hour').size()
|
| 1196 |
-
if not rear_sore_total.empty:
|
| 1197 |
-
dominant_hour_rear_sore = rear_sore_total.idxmax()
|
| 1198 |
-
dominant_count_rear_sore = rear_sore_total.max()
|
| 1199 |
-
insight_lines.append(f"β’ Rear Shift 2 (18:00β06:00): Peak at {dominant_hour_rear_sore:02d}:00 ({dominant_count_rear_sore} alarms)")
|
| 1200 |
-
|
| 1201 |
-
insight_text = "\n".join(insight_lines)
|
| 1202 |
-
|
| 1203 |
-
# =============== DISPLAY INSIGHT ===============
|
| 1204 |
-
st.markdown(f"""
|
| 1205 |
-
<div class="insight-box">
|
| 1206 |
-
<div class="content">
|
| 1207 |
-
{insight_text}
|
| 1208 |
-
</div>
|
| 1209 |
-
</div>
|
| 1210 |
-
""", unsafe_allow_html=True)
|
| 1211 |
-
# ================= OBJECTIVE 5 =================
|
| 1212 |
# ================= OBJECTIVE 5 =================
|
| 1213 |
st.markdown('<h3 class="objective-title">OBJECTIVE 5: Insights & Mitigation β How Can Red Pressure Alarms Be Reduced?</h3>', unsafe_allow_html=True)
|
| 1214 |
|
|
@@ -1313,7 +1231,7 @@ insight_text = f"""
|
|
| 1313 |
try:
|
| 1314 |
import requests
|
| 1315 |
import json
|
| 1316 |
-
API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"
|
| 1317 |
prompt = f"""
|
| 1318 |
Role: Fleet Operations Risk Analyst
|
| 1319 |
Insights:
|
|
@@ -1405,10 +1323,4 @@ st.markdown(f"""
|
|
| 1405 |
{risk_mitigation_text.strip()}
|
| 1406 |
</div>
|
| 1407 |
</div>
|
| 1408 |
-
""", unsafe_allow_html=True)
|
| 1409 |
-
# ================= FOOTER =================
|
| 1410 |
-
st.markdown("""
|
| 1411 |
-
<div class="footer">
|
| 1412 |
-
Michelin Mining Tyre Analytics
|
| 1413 |
-
</div>
|
| 1414 |
""", unsafe_allow_html=True)
|
|
|
|
| 1127 |
</div>
|
| 1128 |
</div>
|
| 1129 |
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1130 |
# ================= OBJECTIVE 5 =================
|
| 1131 |
st.markdown('<h3 class="objective-title">OBJECTIVE 5: Insights & Mitigation β How Can Red Pressure Alarms Be Reduced?</h3>', unsafe_allow_html=True)
|
| 1132 |
|
|
|
|
| 1231 |
try:
|
| 1232 |
import requests
|
| 1233 |
import json
|
| 1234 |
+
API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta "
|
| 1235 |
prompt = f"""
|
| 1236 |
Role: Fleet Operations Risk Analyst
|
| 1237 |
Insights:
|
|
|
|
| 1323 |
{risk_mitigation_text.strip()}
|
| 1324 |
</div>
|
| 1325 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1326 |
""", unsafe_allow_html=True)
|