Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,20 +3,19 @@ import pandas as pd
|
|
| 3 |
import xgboost as xgb
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
|
| 7 |
-
os.environ["MPLCONFIGDIR"] = "/tmp"
|
| 8 |
|
| 9 |
-
#
|
| 10 |
booster = xgb.Booster()
|
| 11 |
booster.load_model("xgb_model.json")
|
| 12 |
|
| 13 |
-
#
|
| 14 |
makes = ['FORD', 'TOYOTA', 'HONDA', 'BMW', 'AUDI']
|
| 15 |
transmissions = ['Automatic', 'Manual', 'CVT', 'Auto-Manual', 'Direct Drive']
|
| 16 |
fuels = ['Regular Gasoline', 'Premium Gasoline', 'Diesel', 'Electricity', 'E85', 'CNG']
|
| 17 |
classes = ['SUV', 'Compact Cars', 'Mid-size Cars', 'Large Cars', 'Pickup Trucks', 'Station Wagons']
|
| 18 |
|
| 19 |
-
#
|
| 20 |
def preprocess_input(year, cylinders, displ, make, trany, fuel, vclass):
|
| 21 |
df = pd.DataFrame([{
|
| 22 |
"year": year,
|
|
@@ -29,13 +28,13 @@ def preprocess_input(year, cylinders, displ, make, trany, fuel, vclass):
|
|
| 29 |
}])
|
| 30 |
return xgb.DMatrix(df)
|
| 31 |
|
| 32 |
-
#
|
| 33 |
def predict_mpg(year, cylinders, displ, make, trany, fuel, vclass):
|
| 34 |
input_dmatrix = preprocess_input(year, cylinders, displ, make, trany, fuel, vclass)
|
| 35 |
prediction = booster.predict(input_dmatrix)[0]
|
| 36 |
return f"π Predicted Combined MPG: {prediction:.2f} MPG"
|
| 37 |
|
| 38 |
-
#
|
| 39 |
with gr.Blocks() as demo:
|
| 40 |
gr.Markdown("## π Vehicle MPG Predictor")
|
| 41 |
gr.Markdown("Enter vehicle details to predict Combined MPG")
|
|
|
|
| 3 |
import xgboost as xgb
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
os.environ["MPLCONFIGDIR"] = "/tmp" # Fix for fontconfig error
|
|
|
|
| 7 |
|
| 8 |
+
# Load XGBoost booster from JSON
|
| 9 |
booster = xgb.Booster()
|
| 10 |
booster.load_model("xgb_model.json")
|
| 11 |
|
| 12 |
+
# Define options
|
| 13 |
makes = ['FORD', 'TOYOTA', 'HONDA', 'BMW', 'AUDI']
|
| 14 |
transmissions = ['Automatic', 'Manual', 'CVT', 'Auto-Manual', 'Direct Drive']
|
| 15 |
fuels = ['Regular Gasoline', 'Premium Gasoline', 'Diesel', 'Electricity', 'E85', 'CNG']
|
| 16 |
classes = ['SUV', 'Compact Cars', 'Mid-size Cars', 'Large Cars', 'Pickup Trucks', 'Station Wagons']
|
| 17 |
|
| 18 |
+
# Preprocess input into DMatrix
|
| 19 |
def preprocess_input(year, cylinders, displ, make, trany, fuel, vclass):
|
| 20 |
df = pd.DataFrame([{
|
| 21 |
"year": year,
|
|
|
|
| 28 |
}])
|
| 29 |
return xgb.DMatrix(df)
|
| 30 |
|
| 31 |
+
# Predict MPG
|
| 32 |
def predict_mpg(year, cylinders, displ, make, trany, fuel, vclass):
|
| 33 |
input_dmatrix = preprocess_input(year, cylinders, displ, make, trany, fuel, vclass)
|
| 34 |
prediction = booster.predict(input_dmatrix)[0]
|
| 35 |
return f"π Predicted Combined MPG: {prediction:.2f} MPG"
|
| 36 |
|
| 37 |
+
# Gradio UI
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
gr.Markdown("## π Vehicle MPG Predictor")
|
| 40 |
gr.Markdown("Enter vehicle details to predict Combined MPG")
|