slyskawa commited on
Commit
e386040
1 Parent(s): 8505c9d

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +75 -0
  2. cali_map.png +0 -0
  3. otterDot.png +0 -0
  4. working_model.joblib +3 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from joblib import load
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+
7
+ #import ML model
8
+ ml_model = load('working_model.joblib')
9
+
10
+ #load map of housing
11
+ cali_image = Image.open('cali_map.png')
12
+ otterDot_image = Image.open('/content/otterDot.png')
13
+
14
+ #input sliders
15
+ input_module1 = gr.Slider(-124.35, -114.35, step=0.25, label="Longitude")
16
+ input_module2 = gr.Slider(32, 41, step=0.25, label="Latitude")
17
+ input_module3 = gr.Slider(1, 52, step=1, label="Housing Median Age")
18
+ input_module4 = gr.Slider(1, 39996, step=12, label="Total Rooms")
19
+ input_module5 = gr.Slider(1, 6441, step=1, label="Total Bedrooms")
20
+ input_module6 = gr.Slider(3, 35678, step=50, label="Population")
21
+ input_module7 = gr.Slider(1, 6081, step=10, label="Households")
22
+ input_module8 = gr.Slider(0, 15, step=0.1, label="Median Income")
23
+
24
+ #output modules
25
+ output_module1 = gr.Textbox(label = "Predicted Housing Price")
26
+ output_module2 = gr.Image(label = "California Housing Map")
27
+
28
+ #function
29
+ def predict(longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income):
30
+ input_features = np.array([longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income])
31
+ prediction = ml_model.predict([input_features])
32
+
33
+ #output 1 handling
34
+ output1 = f"${prediction[0]:,.2f}"
35
+
36
+ #output2 handling
37
+ calimap = cali_image.copy()
38
+ lon_min,lon_max=-124,-114
39
+ lat_min,lat_max=32,42
40
+ x_min,x_max=125,744
41
+ y_min,y_max=86,625
42
+ scale_x=(x_max-x_min)/(lon_max-lon_min)
43
+ scale_y=(y_max-y_min)/(lat_max-lat_min)
44
+ def longlat_to_img(longitude,latitude):
45
+ x=(longitude-lon_min)*scale_x+x_min
46
+ y=(lat_max-latitude)*scale_y+y_min
47
+ return int(x),int(y)
48
+ x,y=longlat_to_img(longitude,latitude)
49
+ calimap.paste(otterDot_image,(x-otterDot_image.width//2,y-otterDot_image.height//2),otterDot_image)
50
+ output2 = calimap
51
+
52
+ #return
53
+ return output1,output2
54
+
55
+ examples = [
56
+ [-122.24, 37.85, 52.0, 1467.0, 190.0, 496.0, 177.0, 7.2574, 352100.0],
57
+ [-122.25, 37.84, 52.0, 2535.0, 489.0, 1094.0, 514.0, 3.6591, 299200.0],
58
+ [-118.13, 33.87, 45.0, 1606.0, 300.0, 735.0, 295.0, 4.6765, 198400.0],
59
+ [-118.14, 33.87, 44.0, 1661.0, 315.0, 985.0, 319.0, 4.3942, 219500.0],
60
+ [-116.19, 33.67, 16.0, 1859.0, 476.0, 1994.0, 477.0, 1.7297, 67500.0],
61
+ [-114.56, 33.69, 17.0, 720.0, 174.0, 333.0, 117.0, 1.6509, 85700.0],
62
+ [-114.57, 33.64, 14.0, 1501.0, 337.0, 515.0, 226.0, 3.1917, 73400.0],
63
+ [-120.92, 37.65, 23.0, 505.0, 124.0, 163.0, 129.0, 1.3696, 275000.0],
64
+ [-116.94, 32.78, 17.0, 13559.0, 2656.0, 6990.0, 2533.0, 3.434, 193200.0],
65
+ [-120.98, 37.62, 26.0, 3819.0, 955.0, 3010.0, 932.0, 1.9206, 81300.0]
66
+ ]
67
+
68
+
69
+ gr.Interface(fn=predict,
70
+ inputs=[input_module1, input_module2, input_module3,
71
+ input_module4, input_module5, input_module6,
72
+ input_module7,input_module8],
73
+ outputs=[output_module1, output_module2],examples = examples
74
+ ).launch(debug=True)
75
+
cali_map.png ADDED
otterDot.png ADDED
working_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c165613915309f29c2c7cca62052dad4d5405963e89104d5aa0e4eec5440882
3
+ size 2518870