SHELLAPANDIANGANHUNGING commited on
Commit
a82b5e2
·
verified ·
1 Parent(s): 17f10fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -50
app.py CHANGED
@@ -1,9 +1,6 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import numpy as np
4
- import plotly.express as px
5
- import plotly.graph_objects as go
6
- from sklearn.linear_model import LinearRegression
7
 
8
  # ================= LOAD DATA =================
9
  try:
@@ -23,7 +20,6 @@ except FileNotFoundError:
23
  print("⚠️ File df_final.xlsx not found. Running with dummy data.")
24
 
25
  # ================= SIMULASI PRESSURE BERDASARKAN GRADIEN =================
26
- # Definisikan rumus gradien berdasarkan tabel Anda
27
  pressure_formulas = {
28
  (10, 'High', 'Min'): (76.658370666499, 0.424510125965938),
29
  (10, 'High', 'Max'): (81.0954797166173, 0.445533183),
@@ -41,50 +37,89 @@ def calculate_pressure(tyre_type, temp, condition, min_max):
41
  return intercept + gradient * temp
42
  return None
43
 
44
- # ================= GRADIO INTERFACE =================
45
- with gr.Blocks(title="Michelin Mining Tyre Analytics - Simulation") as demo:
46
- gr.Markdown("""
47
- # 🛞 Michelin Mining Tyre Analytics — Objective 6
48
- ### Simulasi Tekanan Ban Berdasarkan Suhu & Jenis Ban
49
- Masukkan suhu saat ini dan pilih jenis ban untuk mendapatkan rekomendasi tekanan ideal.
50
- """)
51
-
52
- with gr.Row():
53
- tyre_type = gr.Radio(["10 (Depan)", "11 (Belakang)"], label="Jenis Ban", value="10 (Depan)")
54
- temperature = gr.Slider(40, 70, value=54, step=0.5, label="Suhu Saat Ini (°C)")
55
-
56
- with gr.Row():
57
- btn_simulate = gr.Button("Simulasikan Tekanan")
58
-
59
- with gr.Row():
60
- output = gr.HTML(label="Hasil Simulasi")
61
-
62
- def simulate_pressure(tyres, temp):
63
- tyre_num = int(tyres.split()[0])
64
- p_min_high = calculate_pressure(tyre_num, temp, 'High', 'Min')
65
- p_max_high = calculate_pressure(tyre_num, temp, 'High', 'Max')
66
- p_min_low = calculate_pressure(tyre_num, temp, 'Low', 'Min')
67
- p_max_low = calculate_pressure(tyre_num, temp, 'Low', 'Max')
68
-
69
- if p_min_high is None or p_max_high is None or p_min_low is None or p_max_low is None:
70
- return "<p style='color:red;'>❌ Tidak dapat menghitung tekanan. Periksa input.</p>"
71
-
72
- # Rekomendasi: Jaga tekanan antara P Min Low dan P Max High
73
- recommendation = f"""
74
- <div style="background:#f9f9f9; padding:15px; border-radius:8px; font-family:Segoe UI;">
75
- <h4>📊 Hasil Simulasi untuk Ban {tyres} pada Suhu {temp}°C</h4>
76
- <p><strong>P Min saat Low Pressure:</strong> {p_min_low:.1f} psi</p>
77
- <p><strong>P Max saat Low Pressure:</strong> {p_max_low:.1f} psi</p>
78
- <p><strong>P Min saat High Pressure:</strong> {p_min_high:.1f} psi</p>
79
- <p><strong>P Max saat High Pressure:</strong> {p_max_high:.1f} psi</p>
80
- <hr>
81
- <p>✅ <strong>Rekomendasi Tekanan Ideal:</strong> Isi angin antara <strong>{p_min_low:.1f} – {p_max_high:.1f} psi</strong> untuk menghindari alarm Amber/Red.</p>
82
- <p>⚠️ Jika tekanan saat ini < {p_min_low:.1f} psi → risiko <strong>Low Pressure</strong>.</p>
83
- <p>⚠️ Jika tekanan saat ini > {p_max_high:.1f} psi → risiko <strong>High Pressure</strong>.</p>
84
- </div>
85
- """
86
- return recommendation
87
-
88
- btn_simulate.click(simulate_pressure, inputs=[tyre_type, temperature], outputs=output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
- demo.launch()
 
 
 
 
 
1
  import gradio as gr
2
  import pandas as pd
3
  import numpy as np
 
 
 
4
 
5
  # ================= LOAD DATA =================
6
  try:
 
20
  print("⚠️ File df_final.xlsx not found. Running with dummy data.")
21
 
22
  # ================= SIMULASI PRESSURE BERDASARKAN GRADIEN =================
 
23
  pressure_formulas = {
24
  (10, 'High', 'Min'): (76.658370666499, 0.424510125965938),
25
  (10, 'High', 'Max'): (81.0954797166173, 0.445533183),
 
37
  return intercept + gradient * temp
38
  return None
39
 
40
+ # ================= CUSTOM CSS (Dark Theme Premium) =================
41
+ custom_css = """
42
+ <style>
43
+ body {
44
+ background: #000000;
45
+ color: #ffffff;
46
+ font-family: 'Segoe UI', system-ui, sans-serif;
47
+ }
48
+ .gradio-container {
49
+ background: #000000 !important;
50
+ padding: 20px;
51
+ }
52
+ h1, h2, h3, h4, h5, h6 {
53
+ color: #ffffff !important;
54
+ }
55
+ label {
56
+ color: #cccccc !important;
57
+ }
58
+ input, select, button {
59
+ background: #1a1a1a !important;
60
+ color: #ffffff !important;
61
+ border: 1px solid #333333 !important;
62
+ border-radius: 8px !important;
63
+ }
64
+ button {
65
+ background: #003A8F !important;
66
+ color: white !important;
67
+ font-weight: bold;
68
+ padding: 10px 20px;
69
+ transition: all 0.2s ease;
70
+ }
71
+ button:hover {
72
+ background: #002d6b !important;
73
+ transform: translateY(-1px);
74
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
75
+ }
76
+ .gradio-box {
77
+ background: #121212 !important;
78
+ border: 1px solid #333333 !important;
79
+ border-radius: 12px !important;
80
+ padding: 20px !important;
81
+ margin: 10px 0 !important;
82
+ }
83
+ .gradio-markdown {
84
+ color: #ffffff !important;
85
+ }
86
+ .gradio-slider .track {
87
+ background: #FFD100 !important;
88
+ }
89
+ .gradio-slider .thumb {
90
+ background: #FFD100 !important;
91
+ border: 2px solid #000000 !important;
92
+ }
93
+ .output-area {
94
+ background: #1e1e1e !important;
95
+ border: 1px solid #333333 !important;
96
+ border-radius: 12px !important;
97
+ padding: 20px !important;
98
+ margin-top: 20px !important;
99
+ font-family: 'Courier New', monospace;
100
+ font-size: 14px;
101
+ line-height: 1.6;
102
+ }
103
+ .output-area p {
104
+ margin: 5px 0;
105
+ }
106
+ .output-area .recommendation {
107
+ color: #00FF00;
108
+ font-weight: bold;
109
+ }
110
+ .output-area .warning {
111
+ color: #FFA500;
112
+ font-weight: bold;
113
+ }
114
+ .output-area .danger {
115
+ color: #FF0000;
116
+ font-weight: bold;
117
+ }
118
+ </style>
119
+ """
120
 
121
+ # ================= GRADIO INTERFACE =================
122
+ with gr.Blocks(title="Michelin Mining Tyre Analytics — Objective 6", css=custom_css) as demo:
123
+ gr.HTML("""
124
+ <div style="text-align:center; padding:20px;">
125
+ <img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij4KICA8cGF0aCBmaWxsPSIjMDAzQTg4IiBkPSJNMjAgMTVjLTEuMSAwLTIuMi0uOS0yLjItMi4yaC0xLjRjLS4xIDAtLjIuMS0uMi4yaC0xLjRjLS4xIDAtLjIuMS0uMi4yaC0xLjRjLS4xIDAtLjIuMS0uMi4yaC0xLjRjLS4xIDAtLjIuMS0uMi4yaC0xLjRjLS4xIDAtLjIuMS0uMi4yaC0xLjRjLS4xIDAtLjI