GimhanC99 commited on
Commit
d4e8c2f
·
verified ·
1 Parent(s): dcbb26f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Load the model
6
+ model = joblib.load("train_model.pkl")
7
+
8
+ # Define input handler
9
+ def predict_price(make_year, mileage_kmpl, engine_cc, owner_count, accidents_reported,
10
+ fuel_type, brand, transmission, color, insurance_valid):
11
+
12
+ # One-hot encoding
13
+ fuel_dict = {'Diesel': [1, 0, 0], 'Electric': [0, 1, 0], 'Petrol': [0, 0, 1]}
14
+ brand_dict = {
15
+ 'BMW': [1,0,0,0,0,0,0,0,0,0],
16
+ 'Chevrolet': [0,1,0,0,0,0,0,0,0,0],
17
+ 'Ford': [0,0,1,0,0,0,0,0,0,0],
18
+ 'Honda': [0,0,0,1,0,0,0,0,0,0],
19
+ 'Hyundai': [0,0,0,0,1,0,0,0,0,0],
20
+ 'Kia': [0,0,0,0,0,1,0,0,0,0],
21
+ 'Nissan': [0,0,0,0,0,0,1,0,0,0],
22
+ 'Tesla': [0,0,0,0,0,0,0,1,0,0],
23
+ 'Toyota': [0,0,0,0,0,0,0,0,1,0],
24
+ 'Volkswagen': [0,0,0,0,0,0,0,0,0,1]
25
+ }
26
+ trans_dict = {'Automatic': [1, 0], 'Manual': [0, 1]}
27
+ color_dict = {
28
+ 'Black':[1,0,0,0,0,0], 'Blue':[0,1,0,0,0,0], 'Gray':[0,0,1,0,0,0],
29
+ 'Red':[0,0,0,1,0,0], 'Silver':[0,0,0,0,1,0], 'White':[0,0,0,0,0,1]
30
+ }
31
+ insurance_dict = {'No': [1, 0], 'Yes': [0, 1]}
32
+
33
+ # Combine all features
34
+ features = [
35
+ make_year, mileage_kmpl, engine_cc, owner_count, accidents_reported
36
+ ] + fuel_dict[fuel_type] + brand_dict[brand] + trans_dict[transmission] + color_dict[color] + insurance_dict[insurance_valid]
37
+
38
+ prediction = model.predict([features])[0]
39
+ return round(prediction, 2)
40
+
41
+ # Gradio UI
42
+ gr.Interface(
43
+ fn=predict_price,
44
+ inputs=[
45
+ gr.Number(label="Make Year"),
46
+ gr.Number(label="Mileage (km/l)"),
47
+ gr.Number(label="Engine Capacity (cc)"),
48
+ gr.Slider(1, 5, step=1, label="Owner Count"),
49
+ gr.Slider(0, 10, step=1, label="Accidents Reported"),
50
+ gr.Radio(choices=["Diesel", "Electric", "Petrol"], label="Fuel Type"),
51
+ gr.Dropdown(choices=[
52
+ 'BMW', 'Chevrolet', 'Ford', 'Honda', 'Hyundai', 'Kia', 'Nissan', 'Tesla', 'Toyota', 'Volkswagen'
53
+ ], label="Brand"),
54
+ gr.Radio(choices=["Automatic", "Manual"], label="Transmission"),
55
+ gr.Dropdown(choices=["Black", "Blue", "Gray", "Red", "Silver", "White"], label="Color"),
56
+ gr.Radio(choices=["Yes", "No"], label="Insurance Valid")
57
+ ],
58
+ outputs=gr.Number(label="Predicted Price ($)"),
59
+ title="🚗 Used Car Price Prediction"
60
+ ).launch()