Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,66 +1,59 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
# Load
|
| 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 |
-
gr.Number(label="
|
| 42 |
-
gr.Textbox(label="
|
| 43 |
-
gr.Textbox(label="
|
| 44 |
-
gr.Textbox(label="
|
| 45 |
-
gr.Textbox(label="
|
| 46 |
-
gr.
|
| 47 |
-
gr.
|
| 48 |
-
gr.Textbox(label="
|
| 49 |
-
gr.
|
| 50 |
-
gr.Number(label="
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
outputs=gr.Textbox(label="Prediction"),
|
| 61 |
-
title="🚗 Car Price Prediction",
|
| 62 |
-
description="Enter car details to predict the estimated selling price."
|
| 63 |
-
)
|
| 64 |
-
|
| 65 |
-
if __name__ == "__main__":
|
| 66 |
-
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle as pkl
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# === Load Preprocessor and Model ===
|
| 6 |
+
preprocessor = pkl.load(open("prepocessr.pkl", "rb"))
|
| 7 |
+
model = pkl.load(open("rfrc.pkl", "rb"))
|
| 8 |
+
|
| 9 |
+
# === Define Prediction Function ===
|
| 10 |
+
def predict(make, model_car, year, trim, body, transmission, state, condition, odometer, color, interior, mmr):
|
| 11 |
+
# Put inputs into a DataFrame with the same column names as training
|
| 12 |
+
input_df = pd.DataFrame([{
|
| 13 |
+
"make": make,
|
| 14 |
+
"model": model_car,
|
| 15 |
+
"year": year,
|
| 16 |
+
"trim": trim,
|
| 17 |
+
"body": body,
|
| 18 |
+
"transmission": transmission,
|
| 19 |
+
"state": state,
|
| 20 |
+
"condition": condition,
|
| 21 |
+
"odometer": odometer,
|
| 22 |
+
"color": color,
|
| 23 |
+
"interior": interior,
|
| 24 |
+
"mmr": mmr
|
| 25 |
+
}])
|
| 26 |
+
|
| 27 |
+
# Apply preprocessing
|
| 28 |
+
X_proc = preprocessor.transform(input_df)
|
| 29 |
+
|
| 30 |
+
# Predict with model
|
| 31 |
+
prediction = model.predict(X_proc)[0]
|
| 32 |
+
|
| 33 |
+
return f"Predicted Selling Price: ${prediction:,.2f}"
|
| 34 |
+
|
| 35 |
+
# === Gradio Interface ===
|
| 36 |
+
iface = gr.Interface(
|
| 37 |
+
fn=predict,
|
| 38 |
+
inputs=[
|
| 39 |
+
gr.Textbox(label="Make"),
|
| 40 |
+
gr.Textbox(label="Model"),
|
| 41 |
+
gr.Number(label="Year"),
|
| 42 |
+
gr.Textbox(label="Trim"),
|
| 43 |
+
gr.Textbox(label="Body"),
|
| 44 |
+
gr.Textbox(label="Transmission"),
|
| 45 |
+
gr.Textbox(label="State"),
|
| 46 |
+
gr.Number(label="Condition"),
|
| 47 |
+
gr.Number(label="Odometer"),
|
| 48 |
+
gr.Textbox(label="Color"),
|
| 49 |
+
gr.Textbox(label="Interior"),
|
| 50 |
+
gr.Number(label="MMR"),
|
| 51 |
+
],
|
| 52 |
+
outputs=gr.Textbox(label="Prediction"),
|
| 53 |
+
title="Car Price Prediction App",
|
| 54 |
+
description="Enter car details to predict the selling price."
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# Launch app
|
| 58 |
+
if __name__ == "__main__":
|
| 59 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|