Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,111 +2,112 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
-
# ================= LOAD DATA =================
|
|
|
|
|
|
|
|
|
|
| 6 |
try:
|
| 7 |
df = pd.read_excel("df_final.xlsx", sheet_name="Sheet1")
|
| 8 |
-
|
| 9 |
-
df.columns = df.columns.str.replace("Â", "")
|
| 10 |
for col in df.select_dtypes(include='object').columns:
|
| 11 |
-
df[col] = df[col].astype(str).str.replace("Â", "")
|
| 12 |
-
# Parse datetime
|
| 13 |
df['Time'] = pd.to_datetime(df['Time'], errors='coerce')
|
| 14 |
df = df.dropna(subset=['Time'])
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
(
|
| 31 |
-
(
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
if (tyre_type, condition, min_max) in pressure_formulas:
|
| 36 |
-
intercept, gradient = pressure_formulas[(tyre_type, condition, min_max)]
|
| 37 |
-
return intercept + gradient * temp
|
| 38 |
-
return None
|
| 39 |
-
|
| 40 |
-
# ================= CUSTOM CSS (Dark Theme Premium) =================
|
| 41 |
custom_css = """
|
| 42 |
-
body {
|
| 43 |
-
background: #000000;
|
| 44 |
-
color: #
|
| 45 |
font-family: 'Segoe UI', system-ui, sans-serif;
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
.gradio-container {
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
}
|
| 85 |
-
.
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
border:
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
font-family: 'Courier New', monospace;
|
| 99 |
-
font-size: 14px;
|
| 100 |
line-height: 1.6;
|
| 101 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
.output-area p {
|
| 103 |
-
margin:
|
| 104 |
}
|
| 105 |
-
.output-area .
|
| 106 |
color: #00FF00;
|
| 107 |
font-weight: bold;
|
| 108 |
}
|
| 109 |
-
.output-area .
|
| 110 |
color: #FFA500;
|
| 111 |
font-weight: bold;
|
| 112 |
}
|
|
@@ -114,64 +115,99 @@ button:hover {
|
|
| 114 |
color: #FF0000;
|
| 115 |
font-weight: bold;
|
| 116 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
"""
|
| 118 |
|
| 119 |
-
# ================= GRADIO
|
| 120 |
with gr.Blocks(title="Michelin Mining Tyre Analytics — Objective 6", css=custom_css) as demo:
|
| 121 |
-
gr.
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
""")
|
| 126 |
|
| 127 |
-
with gr.
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
)
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
| 167 |
<hr>
|
| 168 |
-
<
|
| 169 |
-
<p
|
| 170 |
-
<p class="
|
| 171 |
-
</
|
|
|
|
|
|
|
|
|
|
| 172 |
"""
|
| 173 |
-
return
|
| 174 |
|
| 175 |
-
|
| 176 |
|
| 177 |
demo.launch()
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
# ================= LOAD DATA — AMBIL TEKANAN & WAKTU TERAKHIR =================
|
| 6 |
+
last_pressure = 85.0
|
| 7 |
+
last_time = "–"
|
| 8 |
+
|
| 9 |
try:
|
| 10 |
df = pd.read_excel("df_final.xlsx", sheet_name="Sheet1")
|
| 11 |
+
df.columns = df.columns.str.replace("Â", "", regex=False)
|
|
|
|
| 12 |
for col in df.select_dtypes(include='object').columns:
|
| 13 |
+
df[col] = df[col].astype(str).str.replace("Â", "", regex=False)
|
|
|
|
| 14 |
df['Time'] = pd.to_datetime(df['Time'], errors='coerce')
|
| 15 |
df = df.dropna(subset=['Time'])
|
| 16 |
+
|
| 17 |
+
if not df.empty:
|
| 18 |
+
last_row = df.sort_values('Time').iloc[-1]
|
| 19 |
+
last_pressure = float(last_row['Pressure']) if pd.notna(last_row.get('Pressure')) else 85.0
|
| 20 |
+
last_time = last_row['Time'].strftime("%H:%M")
|
| 21 |
+
except Exception as e:
|
| 22 |
+
pass # tetap pakai default jika gagal
|
| 23 |
+
|
| 24 |
+
# ================= BATAS AMAN (SESUAI STANDAR OPERASIONAL) =================
|
| 25 |
+
red_low = 70.0
|
| 26 |
+
amber_low = 75.0
|
| 27 |
+
amber_high = 95.0
|
| 28 |
+
red_high = 100.0
|
| 29 |
+
|
| 30 |
+
def get_safe_fill_range(last_p):
|
| 31 |
+
lower = max(last_p - 10, amber_low + 0.5)
|
| 32 |
+
upper = min(last_p + 10, amber_high - 0.5)
|
| 33 |
+
return round(lower, 1), round(upper, 1)
|
| 34 |
+
|
| 35 |
+
# ================= CUSTOM CSS — BERSIH, PROFESIONAL, SATU HALAMAN =================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
custom_css = """
|
| 37 |
+
body, .gradio-container {
|
| 38 |
+
background: #000000 !important;
|
| 39 |
+
color: #FFFFFF !important;
|
| 40 |
font-family: 'Segoe UI', system-ui, sans-serif;
|
| 41 |
+
margin: 0;
|
| 42 |
+
padding: 0;
|
| 43 |
}
|
| 44 |
.gradio-container {
|
| 45 |
+
max-width: 100% !important;
|
| 46 |
+
height: 100vh !important;
|
| 47 |
+
display: flex;
|
| 48 |
+
flex-direction: column;
|
| 49 |
+
align-items: center;
|
| 50 |
+
justify-content: flex-start;
|
| 51 |
+
}
|
| 52 |
+
#title-box {
|
| 53 |
+
background: #003A8F;
|
| 54 |
+
color: white;
|
| 55 |
+
padding: 16px 32px;
|
| 56 |
+
border-radius: 12px;
|
| 57 |
+
margin-bottom: 32px;
|
| 58 |
+
text-align: center;
|
| 59 |
+
width: 100%;
|
| 60 |
+
max-width: 800px;
|
| 61 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
|
| 62 |
+
}
|
| 63 |
+
#title-box h1 {
|
| 64 |
+
margin: 0;
|
| 65 |
+
font-size: 28px;
|
| 66 |
+
font-weight: 700;
|
| 67 |
+
}
|
| 68 |
+
.form-section {
|
| 69 |
+
display: flex;
|
| 70 |
+
flex-direction: column;
|
| 71 |
+
align-items: flex-start;
|
| 72 |
+
width: 100%;
|
| 73 |
+
max-width: 800px;
|
| 74 |
+
gap: 24px;
|
| 75 |
+
}
|
| 76 |
+
.control-row {
|
| 77 |
+
display: flex;
|
| 78 |
+
gap: 24px;
|
| 79 |
+
width: 100%;
|
| 80 |
+
align-items: center;
|
| 81 |
+
}
|
| 82 |
+
.control-row > div {
|
| 83 |
+
flex: 1;
|
| 84 |
+
min-width: 200px;
|
| 85 |
+
}
|
| 86 |
+
.gradio-html, .output-area {
|
| 87 |
+
width: 100%;
|
| 88 |
+
max-width: 800px;
|
| 89 |
+
background: #121212;
|
| 90 |
+
border: 1px solid #333;
|
| 91 |
+
border-radius: 12px;
|
| 92 |
+
padding: 24px;
|
| 93 |
+
margin-top: 16px;
|
| 94 |
+
font-size: 18px;
|
|
|
|
|
|
|
| 95 |
line-height: 1.6;
|
| 96 |
}
|
| 97 |
+
.output-area h3 {
|
| 98 |
+
color: #FFD100;
|
| 99 |
+
margin: 16px 0 12px 0;
|
| 100 |
+
font-size: 22px;
|
| 101 |
+
font-weight: 600;
|
| 102 |
+
}
|
| 103 |
.output-area p {
|
| 104 |
+
margin: 10px 0;
|
| 105 |
}
|
| 106 |
+
.output-area .safe {
|
| 107 |
color: #00FF00;
|
| 108 |
font-weight: bold;
|
| 109 |
}
|
| 110 |
+
.output-area .caution {
|
| 111 |
color: #FFA500;
|
| 112 |
font-weight: bold;
|
| 113 |
}
|
|
|
|
| 115 |
color: #FF0000;
|
| 116 |
font-weight: bold;
|
| 117 |
}
|
| 118 |
+
.gr-button {
|
| 119 |
+
background: #003A8F !important;
|
| 120 |
+
color: white !important;
|
| 121 |
+
font-weight: bold;
|
| 122 |
+
font-size: 18px !important;
|
| 123 |
+
padding: 12px 32px !important;
|
| 124 |
+
border-radius: 8px !important;
|
| 125 |
+
border: none !important;
|
| 126 |
+
width: auto !important;
|
| 127 |
+
margin-top: 12px;
|
| 128 |
+
}
|
| 129 |
+
.gr-button:hover {
|
| 130 |
+
background: #002D6B !important;
|
| 131 |
+
transform: scale(1.03);
|
| 132 |
+
box-shadow: 0 4px 12px rgba(0, 58, 143, 0.4);
|
| 133 |
+
}
|
| 134 |
+
label {
|
| 135 |
+
color: #CCCCCC !important;
|
| 136 |
+
font-size: 18px !important;
|
| 137 |
+
font-weight: 500;
|
| 138 |
+
}
|
| 139 |
+
input, select {
|
| 140 |
+
font-size: 18px !important;
|
| 141 |
+
}
|
| 142 |
"""
|
| 143 |
|
| 144 |
+
# ================= GRADIO LAYOUT — FULL KIRI, TANPA SIMBOL =================
|
| 145 |
with gr.Blocks(title="Michelin Mining Tyre Analytics — Objective 6", css=custom_css) as demo:
|
| 146 |
+
gr.HTML("""
|
| 147 |
+
<div id="title-box">
|
| 148 |
+
<h1>Michelin Mining Tyre Simulation Pressure</h1>
|
| 149 |
+
</div>
|
| 150 |
""")
|
| 151 |
|
| 152 |
+
with gr.Column(elem_classes="form-section"):
|
| 153 |
+
with gr.Row(elem_classes="control-row"):
|
| 154 |
+
temperature = gr.Slider(
|
| 155 |
+
label="Suhu Saat Ini (°C)",
|
| 156 |
+
minimum=40,
|
| 157 |
+
maximum=70,
|
| 158 |
+
value=54,
|
| 159 |
+
step=0.5,
|
| 160 |
+
interactive=True
|
| 161 |
+
)
|
| 162 |
+
tyre_type = gr.Radio(
|
| 163 |
+
choices=["10 (Depan)", "11 (Belakang)"],
|
| 164 |
+
label="Jenis Ban",
|
| 165 |
+
value="10 (Depan)",
|
| 166 |
+
interactive=True
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
last_info = gr.Markdown(
|
| 170 |
+
f"Tekanan Terakhir: {last_pressure} psi | Jam: {last_time}"
|
| 171 |
)
|
| 172 |
|
| 173 |
+
btn_submit = gr.Button("Submit", elem_classes="gr-button")
|
| 174 |
+
output = gr.HTML(elem_classes="output-area")
|
| 175 |
+
|
| 176 |
+
# ================= LOGIKA SIMULASI — BERSIH & BERBASIS DATA NYATA =================
|
| 177 |
+
def simulate(tyre_str, temp):
|
| 178 |
+
# Interpolasi sederhana: baseline 54°C → 85 psi, slope 0.42 psi/°C
|
| 179 |
+
ideal = 85.0 + 0.42 * (temp - 54.0)
|
| 180 |
+
ideal = round(ideal, 1)
|
| 181 |
+
|
| 182 |
+
lower_safe, upper_safe = get_safe_fill_range(last_pressure)
|
| 183 |
+
|
| 184 |
+
# Status penilaian
|
| 185 |
+
if ideal < red_low:
|
| 186 |
+
status = '<span class="danger">Risiko Red — Tekanan terlalu rendah</span>'
|
| 187 |
+
elif ideal < amber_low:
|
| 188 |
+
status = '<span class="caution">Risiko Amber — Tekanan mendekati batas bawah</span>'
|
| 189 |
+
elif ideal > red_high:
|
| 190 |
+
status = '<span class="danger">Risiko Red — Tekanan terlalu tinggi</span>'
|
| 191 |
+
elif ideal > amber_high:
|
| 192 |
+
status = '<span class="caution">Risiko Amber — Tekanan mendekati batas atas</span>'
|
| 193 |
+
else:
|
| 194 |
+
status = '<span class="safe">Dalam zona aman</span>'
|
| 195 |
+
|
| 196 |
+
rec_html = f"""
|
| 197 |
+
<h3>Hasil Simulasi</h3>
|
| 198 |
+
<p>Ideal Tekanan pada {temp}°C: {ideal} psi</p>
|
| 199 |
+
<p>Status: {status}</p>
|
| 200 |
<hr>
|
| 201 |
+
<h3>Rekomendasi Isi Ulang</h3>
|
| 202 |
+
<p>Berdasarkan tekanan terakhir ({last_pressure} psi pukul {last_time}):</p>
|
| 203 |
+
<p class="safe">Isi tekanan antara {lower_safe} – {upper_safe} psi</p>
|
| 204 |
+
<p class="caution">Jangan isi kurang dari {amber_low} psi (batas Amber bawah)</p>
|
| 205 |
+
<p class="caution">Jangan isi lebih dari {amber_high} psi (batas Amber atas)</p>
|
| 206 |
+
<p class="danger">Hindari tekanan di bawah {red_low} psi atau di atas {red_high} psi (zona Red)</p>
|
| 207 |
+
<p style="margin-top:16px;"><em>Catatan: Rekomendasi ini mempertahankan margin aman minimal 0.5 psi dari zona Amber.</em></p>
|
| 208 |
"""
|
| 209 |
+
return rec_html
|
| 210 |
|
| 211 |
+
btn_submit.click(simulate, inputs=[tyre_type, temperature], outputs=output)
|
| 212 |
|
| 213 |
demo.launch()
|