Spaces:
Sleeping
Sleeping
File size: 3,003 Bytes
d1719f7 ec53212 d1719f7 ec53212 d1719f7 ec53212 c1fd2f4 ec53212 33b3434 c1fd2f4 ec53212 7daaa75 ec53212 c1fd2f4 ec53212 c1fd2f4 ec53212 d1719f7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 |
import gradio as gr
import pandas as pd
import joblib
# Load model
best_model = joblib.load("xgb_model.pkl")
# Define function
def simulate(
loaded_drv, empty_drv, eng_speed,
empty_stop, loading_stop, loaded_stop,
unit_count, cycle_per_day, unit_payload
):
# Prediction
input_data = {
'loaded_drv_time_percycle': loaded_drv,
'empty_drv_time_percycle': empty_drv,
'Eng_Speed_Ave': eng_speed,
'empty_stop_time_percycle': empty_stop,
'loadingstoptime_percycle': loading_stop,
'loaded_stop_time_percycle': loaded_stop
}
input_df = pd.DataFrame([input_data])
fuel_rate = best_model.predict(input_df)[0]
# Calculations
production_per_day = unit_count * cycle_per_day * unit_payload
fuel_per_day = unit_count * cycle_per_day * fuel_rate
fuel_per_month = 30 * fuel_per_day
return (
f"{fuel_rate:,.2f}",
f"{production_per_day:,.2f}",
f"{fuel_per_day:,.2f}",
f"{fuel_per_month:,.2f}"
)
# Interface
# Use gr.Blocks for custom layout
with gr.Blocks() as interface:
gr.Markdown("## π Fuel - Digital Twin (What-If Simulator)")
gr.Markdown("Adjust inputs to simulate operating conditions and predict production & fuel usage.")
# Top 3-column row for business inputs
with gr.Row():
with gr.Column():
unit_count = gr.Number(value=5, label="Unit Count")
with gr.Column():
cycle_per_day = gr.Number(value=60, label="Cycle Per Day")
with gr.Column():
unit_payload = gr.Number(value=90, label="Unit Payload (Ton)")
# Main 2-column layout: left = input sliders, right = output
with gr.Row():
with gr.Column(): # Left side = input sliders (one column)
loaded_drv = gr.Slider(3, 60, value=18, label="Loaded Drive Time per Cycle")
empty_drv = gr.Slider(2, 51, value=16, label="Empty Drive Time per Cycle")
eng_speed = gr.Slider(1051, 1596, value=1416, label="Engine Speed Average")
empty_stop = gr.Slider(0.2, 24.6, value=4.2, label="Empty Stop Time per Cycle")
loading_stop = gr.Slider(2, 18, value=2, label="Loading Stop Time per Cycle")
loaded_stop = gr.Slider(0.4, 9, value=0.4, label="Loaded Stop Time per Cycle")
submit_btn = gr.Button("Submit")
with gr.Column(): # Right side = output results
output1 = gr.Textbox(label="π Predicted Fuel Rate per Cycle (L)")
output2 = gr.Textbox(label="π¦ Production Per Day (Ton)")
output3 = gr.Textbox(label="β½ Fuel Consumption Per Day (L)")
output4 = gr.Textbox(label="β½ Fuel Consumption Per Month (L)")
submit_btn.click(
simulate,
inputs=[
loaded_drv, empty_drv, eng_speed,
empty_stop, loading_stop, loaded_stop,
unit_count, cycle_per_day, unit_payload
],
outputs=[output1, output2, output3, output4]
)
interface.launch() |