Spaces:
Sleeping
Sleeping
rickyt
commited on
Commit
Β·
ec53212
1
Parent(s):
6d542f0
code changes
Browse files
app.py
CHANGED
|
@@ -2,11 +2,16 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
best_model = joblib.load("xgb_model.pkl")
|
| 7 |
|
| 8 |
-
# Define
|
| 9 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
input_data = {
|
| 11 |
'loaded_drv_time_percycle': loaded_drv,
|
| 12 |
'empty_drv_time_percycle': empty_drv,
|
|
@@ -16,24 +21,58 @@ def predict_fuel_rate(loaded_drv, empty_drv, eng_speed, empty_stop, loading_stop
|
|
| 16 |
'loaded_stop_time_percycle': loaded_stop
|
| 17 |
}
|
| 18 |
input_df = pd.DataFrame([input_data])
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
interface.launch()
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
|
| 5 |
+
# Load model
|
| 6 |
best_model = joblib.load("xgb_model.pkl")
|
| 7 |
|
| 8 |
+
# Define function
|
| 9 |
+
def simulate(
|
| 10 |
+
loaded_drv, empty_drv, eng_speed,
|
| 11 |
+
empty_stop, loading_stop, loaded_stop,
|
| 12 |
+
unit_count, cycle_per_day, unit_payload
|
| 13 |
+
):
|
| 14 |
+
# Prediction
|
| 15 |
input_data = {
|
| 16 |
'loaded_drv_time_percycle': loaded_drv,
|
| 17 |
'empty_drv_time_percycle': empty_drv,
|
|
|
|
| 21 |
'loaded_stop_time_percycle': loaded_stop
|
| 22 |
}
|
| 23 |
input_df = pd.DataFrame([input_data])
|
| 24 |
+
fuel_rate = best_model.predict(input_df)[0]
|
| 25 |
+
|
| 26 |
+
# Calculations
|
| 27 |
+
production_per_day = unit_count * cycle_per_day * unit_payload
|
| 28 |
+
fuel_per_day = unit_count * cycle_per_day * fuel_rate
|
| 29 |
+
|
| 30 |
+
return (
|
| 31 |
+
f"{fuel_rate:,.2f}",
|
| 32 |
+
f"{production_per_day:,.2f}",
|
| 33 |
+
f"{fuel_per_day:,.2f}"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Interface
|
| 37 |
+
# Use gr.Blocks for custom layout
|
| 38 |
+
with gr.Blocks() as interface:
|
| 39 |
+
gr.Markdown("## π Fuel Digital Twin (What-If Simulator)")
|
| 40 |
+
gr.Markdown("Adjust inputs to simulate operating conditions and predict production & fuel usage.")
|
| 41 |
+
|
| 42 |
+
# Top 3-column row for business inputs
|
| 43 |
+
with gr.Row():
|
| 44 |
+
with gr.Column():
|
| 45 |
+
unit_count = gr.Number(value=5, label="Unit Count")
|
| 46 |
+
with gr.Column():
|
| 47 |
+
cycle_per_day = gr.Number(value=60, label="Cycle Per Day")
|
| 48 |
+
with gr.Column():
|
| 49 |
+
unit_payload = gr.Number(value=90, label="Unit Payload (Ton)")
|
| 50 |
+
|
| 51 |
+
# Main 2-column layout: left = input sliders, right = output
|
| 52 |
+
with gr.Row():
|
| 53 |
+
with gr.Column(): # Left side = input sliders (one column)
|
| 54 |
+
loaded_drv = gr.Slider(3, 60, value=18, label="Loaded Drive Time per Cycle")
|
| 55 |
+
empty_drv = gr.Slider(2, 51, value=16, label="Empty Drive Time per Cycle")
|
| 56 |
+
eng_speed = gr.Slider(1051, 1596, value=1416, label="Engine Speed Average")
|
| 57 |
+
empty_stop = gr.Slider(0.2, 24.6, value=4.2, label="Empty Stop Time per Cycle")
|
| 58 |
+
loading_stop = gr.Slider(2, 18, value=2, label="Loading Stop Time per Cycle")
|
| 59 |
+
loaded_stop = gr.Slider(0.4, 9, value=0.4, label="Loaded Stop Time per Cycle")
|
| 60 |
+
submit_btn = gr.Button("Submit")
|
| 61 |
+
|
| 62 |
+
with gr.Column(): # Right side = output results
|
| 63 |
+
output1 = gr.Textbox(label="π Predicted Fuel Rate per Cycle (L)")
|
| 64 |
+
output2 = gr.Textbox(label="π¦ Production Per Day (Ton)")
|
| 65 |
+
output3 = gr.Textbox(label="β½ Fuel Consumption Per Day (L)")
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
submit_btn.click(
|
| 69 |
+
simulate,
|
| 70 |
+
inputs=[
|
| 71 |
+
loaded_drv, empty_drv, eng_speed,
|
| 72 |
+
empty_stop, loading_stop, loaded_stop,
|
| 73 |
+
unit_count, cycle_per_day, unit_payload
|
| 74 |
+
],
|
| 75 |
+
outputs=[output1, output2, output3]
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
interface.launch()
|