Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import joblib
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
|
6 |
+
# Download the model from Hugging Face hub
|
7 |
+
model_filename = hf_hub_download(repo_id="poudel/fuel-burn-predictor", filename="fuel_burn_model.pkl")
|
8 |
+
|
9 |
+
# Load the model
|
10 |
+
model = joblib.load(model_filename)
|
11 |
+
|
12 |
+
# Define the prediction function
|
13 |
+
def predict_fuel_burn_kg(truck_id, kms, litros):
|
14 |
+
# Map truck ID input to match the expected format
|
15 |
+
truck_ids = {'Truck_ID_MTP3482': 0, 'Truck_ID_MTP5052': 1, 'Truck_ID_MTP5126': 2}
|
16 |
+
truck_id_num = truck_ids.get(truck_id, -1) # Convert Truck ID to numerical representation
|
17 |
+
|
18 |
+
# Create a dataframe with the input data
|
19 |
+
input_data = pd.DataFrame({
|
20 |
+
'Truck_ID': [truck_id_num],
|
21 |
+
'Kms': [kms],
|
22 |
+
'Litros': [litros]
|
23 |
+
})
|
24 |
+
|
25 |
+
# Predict fuel burn in liters
|
26 |
+
prediction_litros = model.predict(input_data)
|
27 |
+
|
28 |
+
# Convert liters to kilograms (using diesel density of 0.835 kg/liter)
|
29 |
+
density_kg_per_liter = 0.835
|
30 |
+
prediction_kg = prediction_litros[0] * density_kg_per_liter
|
31 |
+
|
32 |
+
return round(prediction_kg, 2)
|
33 |
+
|
34 |
+
# Create the Gradio interface
|
35 |
+
app = gr.Interface(
|
36 |
+
fn=predict_fuel_burn_kg,
|
37 |
+
inputs=[
|
38 |
+
gr.Dropdown(['Truck_ID_MTP3482', 'Truck_ID_MTP5052', 'Truck_ID_MTP5126'], label="Truck ID"),
|
39 |
+
gr.Number(label="Kilometers Driven"),
|
40 |
+
gr.Number(label="Fuel Consumed (Liters)")
|
41 |
+
],
|
42 |
+
outputs=gr.Number(label="Predicted Fuel Burn (kg)"),
|
43 |
+
title="Truck Fuel Burn Predictor",
|
44 |
+
description="Enter the truck ID, kilometers driven, and fuel consumed in liters to predict fuel burn in kilograms."
|
45 |
+
)
|
46 |
+
|
47 |
+
# Launch the Gradio app
|
48 |
+
app.launch()
|