Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -92,14 +92,35 @@ def predict_price(model, brand, model_name, year):
|
|
92 |
'paint_color': 'White' # Default color
|
93 |
}
|
94 |
|
95 |
-
# Calculate age
|
96 |
current_year = datetime.now().year
|
97 |
input_data['age'] = current_year - year
|
98 |
input_data['age_squared'] = input_data['age'] ** 2
|
|
|
99 |
|
100 |
# Prepare the input for the model
|
101 |
input_df = pd.DataFrame([input_data])
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
# Make sure to only include columns that the model expects
|
104 |
model_columns = model.feature_names_in_
|
105 |
input_df = input_df[model_columns]
|
|
|
92 |
'paint_color': 'White' # Default color
|
93 |
}
|
94 |
|
95 |
+
# Calculate age and other required fields
|
96 |
current_year = datetime.now().year
|
97 |
input_data['age'] = current_year - year
|
98 |
input_data['age_squared'] = input_data['age'] ** 2
|
99 |
+
input_data['mileage_per_year'] = 12000 # Assuming average annual mileage
|
100 |
|
101 |
# Prepare the input for the model
|
102 |
input_df = pd.DataFrame([input_data])
|
103 |
|
104 |
+
# Rename columns to match what the model expects
|
105 |
+
input_df = input_df.rename(columns={
|
106 |
+
'make': 'Make',
|
107 |
+
'model': 'Model',
|
108 |
+
'year': 'Year',
|
109 |
+
'trim': 'Trim',
|
110 |
+
'condition': 'Condition',
|
111 |
+
'fuel': 'Fuel',
|
112 |
+
'odometer': 'Odometer',
|
113 |
+
'title_status': 'Title_status',
|
114 |
+
'transmission': 'Transmission',
|
115 |
+
'drive': 'Drive',
|
116 |
+
'size': 'Size',
|
117 |
+
'type': 'Type',
|
118 |
+
'paint_color': 'Paint_color',
|
119 |
+
'age': 'Age',
|
120 |
+
'age_squared': 'Age_squared',
|
121 |
+
'mileage_per_year': 'Mileage_per_year'
|
122 |
+
})
|
123 |
+
|
124 |
# Make sure to only include columns that the model expects
|
125 |
model_columns = model.feature_names_in_
|
126 |
input_df = input_df[model_columns]
|