Sagar Thacker commited on
Commit
6dd5319
·
1 Parent(s): e87a04d

Initial commit

Browse files
Files changed (6) hide show
  1. .gitignore +1 -0
  2. app.py +81 -0
  3. data/zone_lookup.csv +261 -0
  4. models/lin_reg.bin +3 -0
  5. models/model.pkl +3 -0
  6. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .DS_Store
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import random
3
+ import pandas as pd
4
+ import gradio as gr
5
+ from fastai.vision.all import *
6
+
7
+ zone_lookup = pd.read_csv('./data/zone_lookup.csv')
8
+
9
+ with open('./models/lin_reg.bin', 'rb') as handle:
10
+ dv, model = pickle.load(handle)
11
+
12
+ def prepare_features(pickup, dropoff, trip_distance):
13
+ pickupId = zone_lookup[zone_lookup["borough_zone"] == pickup].LocationID
14
+ dropoffId = zone_lookup[zone_lookup["borough_zone"] == dropoff].LocationID
15
+ trip_distance = round(trip_distance, 4)
16
+
17
+ features = {}
18
+ features['PU_DO'] = '%s_%s' % (pickupId, dropoffId)
19
+ features['trip_distance'] = trip_distance
20
+ return features
21
+
22
+ def predict(pickup, dropoff, trip_distance):
23
+ features = prepare_features(pickup, dropoff, trip_distance)
24
+ X = dv.transform(features)
25
+ preds = model.predict(X)
26
+ duration = float(preds[0])
27
+ return "The predicted duration is %.4f minutes." % duration
28
+
29
+ with gr.Blocks() as demo:
30
+ gr.Markdown("Predict Taxi Duration or Classify dog breeds using this demo")
31
+
32
+ with gr.Tab("Predict Taxi Duration"):
33
+ with gr.Row():
34
+ pickup = gr.Dropdown(
35
+ choices=list(zone_lookup["borough_zone"]),
36
+ label="Pickup Location",
37
+ info="The location where the passenger(s) were picked up",
38
+ value=lambda: random.choice(zone_lookup["borough_zone"])
39
+ )
40
+
41
+ dropoff = gr.Dropdown(
42
+ choices=list(zone_lookup["borough_zone"]),
43
+ label="Dropoff Location",
44
+ info="The location where the passenger(s) were dropped off",
45
+ value=lambda: random.choice(zone_lookup["borough_zone"])
46
+ )
47
+
48
+ trip_distance = gr.Slider(
49
+ minimum=0.0,
50
+ maximum=100.0,
51
+ step=0.1,
52
+ label="Trip Distance",
53
+ info="The trip distance in miles calculated by the taximeter",
54
+ value=lambda: random.uniform(0.0, 100.0)
55
+ )
56
+ with gr.Column():
57
+ output = gr.Textbox(label="Output Box")
58
+ predict_btn = gr.Button("Predict")
59
+
60
+ with gr.Tab("Classify Dog Breed"):
61
+ def is_cat(x): return x[0].isupper()
62
+
63
+ learn = load_learner('./models/model.pkl')
64
+
65
+ categories = ('Dog', 'Cat')
66
+
67
+ def classify_image(img):
68
+ pred, idx, probs = learn.predict(img)
69
+ return dict(zip(categories, map(float,probs)))
70
+
71
+ image = gr.inputs.Image(shape=(192, 192))
72
+ label = gr.outputs.Label()
73
+ examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
74
+
75
+ classify_btn = gr.Button("Predict")
76
+
77
+
78
+ predict_btn.click(fn=predict, inputs=[pickup, dropoff, trip_distance], outputs=output, api_name="predict-duration")
79
+ classify_btn.click(fn=classify_image, inputs=image, outputs=label, api_name="classify-dog-breed")
80
+
81
+ demo.launch()
data/zone_lookup.csv ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ LocationID,borough_zone
2
+ 1,EWR - Newark Airport
3
+ 2,Queens - Jamaica Bay
4
+ 3,Bronx - Allerton/Pelham Gardens
5
+ 4,Manhattan - Alphabet City
6
+ 5,Staten Island - Arden Heights
7
+ 6,Staten Island - Arrochar/Fort Wadsworth
8
+ 7,Queens - Astoria
9
+ 8,Queens - Astoria Park
10
+ 9,Queens - Auburndale
11
+ 10,Queens - Baisley Park
12
+ 11,Brooklyn - Bath Beach
13
+ 12,Manhattan - Battery Park
14
+ 13,Manhattan - Battery Park City
15
+ 14,Brooklyn - Bay Ridge
16
+ 15,Queens - Bay Terrace/Fort Totten
17
+ 16,Queens - Bayside
18
+ 17,Brooklyn - Bedford
19
+ 18,Bronx - Bedford Park
20
+ 19,Queens - Bellerose
21
+ 20,Bronx - Belmont
22
+ 21,Brooklyn - Bensonhurst East
23
+ 22,Brooklyn - Bensonhurst West
24
+ 23,Staten Island - Bloomfield/Emerson Hill
25
+ 24,Manhattan - Bloomingdale
26
+ 25,Brooklyn - Boerum Hill
27
+ 26,Brooklyn - Borough Park
28
+ 27,Queens - Breezy Point/Fort Tilden/Riis Beach
29
+ 28,Queens - Briarwood/Jamaica Hills
30
+ 29,Brooklyn - Brighton Beach
31
+ 30,Queens - Broad Channel
32
+ 31,Bronx - Bronx Park
33
+ 32,Bronx - Bronxdale
34
+ 33,Brooklyn - Brooklyn Heights
35
+ 34,Brooklyn - Brooklyn Navy Yard
36
+ 35,Brooklyn - Brownsville
37
+ 36,Brooklyn - Bushwick North
38
+ 37,Brooklyn - Bushwick South
39
+ 38,Queens - Cambria Heights
40
+ 39,Brooklyn - Canarsie
41
+ 40,Brooklyn - Carroll Gardens
42
+ 41,Manhattan - Central Harlem
43
+ 42,Manhattan - Central Harlem North
44
+ 43,Manhattan - Central Park
45
+ 44,Staten Island - Charleston/Tottenville
46
+ 45,Manhattan - Chinatown
47
+ 46,Bronx - City Island
48
+ 47,Bronx - Claremont/Bathgate
49
+ 48,Manhattan - Clinton East
50
+ 49,Brooklyn - Clinton Hill
51
+ 50,Manhattan - Clinton West
52
+ 51,Bronx - Co-Op City
53
+ 52,Brooklyn - Cobble Hill
54
+ 53,Queens - College Point
55
+ 54,Brooklyn - Columbia Street
56
+ 55,Brooklyn - Coney Island
57
+ 56,Queens - Corona
58
+ 58,Bronx - Country Club
59
+ 59,Bronx - Crotona Park
60
+ 60,Bronx - Crotona Park East
61
+ 61,Brooklyn - Crown Heights North
62
+ 62,Brooklyn - Crown Heights South
63
+ 63,Brooklyn - Cypress Hills
64
+ 64,Queens - Douglaston
65
+ 65,Brooklyn - Downtown Brooklyn/MetroTech
66
+ 66,Brooklyn - DUMBO/Vinegar Hill
67
+ 67,Brooklyn - Dyker Heights
68
+ 68,Manhattan - East Chelsea
69
+ 69,Bronx - East Concourse/Concourse Village
70
+ 70,Queens - East Elmhurst
71
+ 71,Brooklyn - East Flatbush/Farragut
72
+ 72,Brooklyn - East Flatbush/Remsen Village
73
+ 73,Queens - East Flushing
74
+ 74,Manhattan - East Harlem North
75
+ 75,Manhattan - East Harlem South
76
+ 76,Brooklyn - East New York
77
+ 77,Brooklyn - East New York/Pennsylvania Avenue
78
+ 78,Bronx - East Tremont
79
+ 79,Manhattan - East Village
80
+ 80,Brooklyn - East Williamsburg
81
+ 81,Bronx - Eastchester
82
+ 82,Queens - Elmhurst
83
+ 83,Queens - Elmhurst/Maspeth
84
+ 84,Staten Island - Eltingville/Annadale/Prince's Bay
85
+ 85,Brooklyn - Erasmus
86
+ 86,Queens - Far Rockaway
87
+ 87,Manhattan - Financial District North
88
+ 88,Manhattan - Financial District South
89
+ 89,Brooklyn - Flatbush/Ditmas Park
90
+ 90,Manhattan - Flatiron
91
+ 91,Brooklyn - Flatlands
92
+ 92,Queens - Flushing
93
+ 93,Queens - Flushing Meadows-Corona Park
94
+ 94,Bronx - Fordham South
95
+ 95,Queens - Forest Hills
96
+ 96,Queens - Forest Park/Highland Park
97
+ 97,Brooklyn - Fort Greene
98
+ 98,Queens - Fresh Meadows
99
+ 99,Staten Island - Freshkills Park
100
+ 100,Manhattan - Garment District
101
+ 101,Queens - Glen Oaks
102
+ 102,Queens - Glendale
103
+ 103,Manhattan - Governor's Island/Ellis Island/Liberty Island
104
+ 106,Brooklyn - Gowanus
105
+ 107,Manhattan - Gramercy
106
+ 108,Brooklyn - Gravesend
107
+ 109,Staten Island - Great Kills
108
+ 110,Staten Island - Great Kills Park
109
+ 111,Brooklyn - Green-Wood Cemetery
110
+ 112,Brooklyn - Greenpoint
111
+ 113,Manhattan - Greenwich Village North
112
+ 114,Manhattan - Greenwich Village South
113
+ 115,Staten Island - Grymes Hill/Clifton
114
+ 116,Manhattan - Hamilton Heights
115
+ 117,Queens - Hammels/Arverne
116
+ 118,Staten Island - Heartland Village/Todt Hill
117
+ 119,Bronx - Highbridge
118
+ 120,Manhattan - Highbridge Park
119
+ 121,Queens - Hillcrest/Pomonok
120
+ 122,Queens - Hollis
121
+ 123,Brooklyn - Homecrest
122
+ 124,Queens - Howard Beach
123
+ 125,Manhattan - Hudson Sq
124
+ 126,Bronx - Hunts Point
125
+ 127,Manhattan - Inwood
126
+ 128,Manhattan - Inwood Hill Park
127
+ 129,Queens - Jackson Heights
128
+ 130,Queens - Jamaica
129
+ 131,Queens - Jamaica Estates
130
+ 132,Queens - JFK Airport
131
+ 133,Brooklyn - Kensington
132
+ 134,Queens - Kew Gardens
133
+ 135,Queens - Kew Gardens Hills
134
+ 136,Bronx - Kingsbridge Heights
135
+ 137,Manhattan - Kips Bay
136
+ 138,Queens - LaGuardia Airport
137
+ 139,Queens - Laurelton
138
+ 140,Manhattan - Lenox Hill East
139
+ 141,Manhattan - Lenox Hill West
140
+ 142,Manhattan - Lincoln Square East
141
+ 143,Manhattan - Lincoln Square West
142
+ 144,Manhattan - Little Italy/NoLiTa
143
+ 145,Queens - Long Island City/Hunters Point
144
+ 146,Queens - Long Island City/Queens Plaza
145
+ 147,Bronx - Longwood
146
+ 148,Manhattan - Lower East Side
147
+ 149,Brooklyn - Madison
148
+ 150,Brooklyn - Manhattan Beach
149
+ 151,Manhattan - Manhattan Valley
150
+ 152,Manhattan - Manhattanville
151
+ 153,Manhattan - Marble Hill
152
+ 154,Brooklyn - Marine Park/Floyd Bennett Field
153
+ 155,Brooklyn - Marine Park/Mill Basin
154
+ 156,Staten Island - Mariners Harbor
155
+ 157,Queens - Maspeth
156
+ 158,Manhattan - Meatpacking/West Village West
157
+ 159,Bronx - Melrose South
158
+ 160,Queens - Middle Village
159
+ 161,Manhattan - Midtown Center
160
+ 162,Manhattan - Midtown East
161
+ 163,Manhattan - Midtown North
162
+ 164,Manhattan - Midtown South
163
+ 165,Brooklyn - Midwood
164
+ 166,Manhattan - Morningside Heights
165
+ 167,Bronx - Morrisania/Melrose
166
+ 168,Bronx - Mott Haven/Port Morris
167
+ 169,Bronx - Mount Hope
168
+ 170,Manhattan - Murray Hill
169
+ 171,Queens - Murray Hill-Queens
170
+ 172,Staten Island - New Dorp/Midland Beach
171
+ 173,Queens - North Corona
172
+ 174,Bronx - Norwood
173
+ 175,Queens - Oakland Gardens
174
+ 176,Staten Island - Oakwood
175
+ 177,Brooklyn - Ocean Hill
176
+ 178,Brooklyn - Ocean Parkway South
177
+ 179,Queens - Old Astoria
178
+ 180,Queens - Ozone Park
179
+ 181,Brooklyn - Park Slope
180
+ 182,Bronx - Parkchester
181
+ 183,Bronx - Pelham Bay
182
+ 184,Bronx - Pelham Bay Park
183
+ 185,Bronx - Pelham Parkway
184
+ 186,Manhattan - Penn Station/Madison Sq West
185
+ 187,Staten Island - Port Richmond
186
+ 188,Brooklyn - Prospect-Lefferts Gardens
187
+ 189,Brooklyn - Prospect Heights
188
+ 190,Brooklyn - Prospect Park
189
+ 191,Queens - Queens Village
190
+ 192,Queens - Queensboro Hill
191
+ 193,Queens - Queensbridge/Ravenswood
192
+ 194,Manhattan - Randalls Island
193
+ 195,Brooklyn - Red Hook
194
+ 196,Queens - Rego Park
195
+ 197,Queens - Richmond Hill
196
+ 198,Queens - Ridgewood
197
+ 199,Bronx - Rikers Island
198
+ 200,Bronx - Riverdale/North Riverdale/Fieldston
199
+ 201,Queens - Rockaway Park
200
+ 202,Manhattan - Roosevelt Island
201
+ 203,Queens - Rosedale
202
+ 204,Staten Island - Rossville/Woodrow
203
+ 205,Queens - Saint Albans
204
+ 206,Staten Island - Saint George/New Brighton
205
+ 207,Queens - Saint Michaels Cemetery/Woodside
206
+ 208,Bronx - Schuylerville/Edgewater Park
207
+ 209,Manhattan - Seaport
208
+ 210,Brooklyn - Sheepshead Bay
209
+ 211,Manhattan - SoHo
210
+ 212,Bronx - Soundview/Bruckner
211
+ 213,Bronx - Soundview/Castle Hill
212
+ 214,Staten Island - South Beach/Dongan Hills
213
+ 215,Queens - South Jamaica
214
+ 216,Queens - South Ozone Park
215
+ 217,Brooklyn - South Williamsburg
216
+ 218,Queens - Springfield Gardens North
217
+ 219,Queens - Springfield Gardens South
218
+ 220,Bronx - Spuyten Duyvil/Kingsbridge
219
+ 221,Staten Island - Stapleton
220
+ 222,Brooklyn - Starrett City
221
+ 223,Queens - Steinway
222
+ 224,Manhattan - Stuy Town/Peter Cooper Village
223
+ 225,Brooklyn - Stuyvesant Heights
224
+ 226,Queens - Sunnyside
225
+ 227,Brooklyn - Sunset Park East
226
+ 228,Brooklyn - Sunset Park West
227
+ 229,Manhattan - Sutton Place/Turtle Bay North
228
+ 230,Manhattan - Times Sq/Theatre District
229
+ 231,Manhattan - TriBeCa/Civic Center
230
+ 232,Manhattan - Two Bridges/Seward Park
231
+ 233,Manhattan - UN/Turtle Bay South
232
+ 234,Manhattan - Union Sq
233
+ 235,Bronx - University Heights/Morris Heights
234
+ 236,Manhattan - Upper East Side North
235
+ 237,Manhattan - Upper East Side South
236
+ 238,Manhattan - Upper West Side North
237
+ 239,Manhattan - Upper West Side South
238
+ 240,Bronx - Van Cortlandt Park
239
+ 241,Bronx - Van Cortlandt Village
240
+ 242,Bronx - Van Nest/Morris Park
241
+ 243,Manhattan - Washington Heights North
242
+ 244,Manhattan - Washington Heights South
243
+ 245,Staten Island - West Brighton
244
+ 246,Manhattan - West Chelsea/Hudson Yards
245
+ 247,Bronx - West Concourse
246
+ 248,Bronx - West Farms/Bronx River
247
+ 249,Manhattan - West Village
248
+ 250,Bronx - Westchester Village/Unionport
249
+ 251,Staten Island - Westerleigh
250
+ 252,Queens - Whitestone
251
+ 253,Queens - Willets Point
252
+ 254,Bronx - Williamsbridge/Olinville
253
+ 255,Brooklyn - Williamsburg (North Side)
254
+ 256,Brooklyn - Williamsburg (South Side)
255
+ 257,Brooklyn - Windsor Terrace
256
+ 258,Queens - Woodhaven
257
+ 259,Bronx - Woodlawn/Wakefield
258
+ 260,Queens - Woodside
259
+ 261,Manhattan - World Trade Center
260
+ 262,Manhattan - Yorkville East
261
+ 263,Manhattan - Yorkville West
models/lin_reg.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b51a38fd7db9b529e6050df04dfceb91c6703502034d02014f9d1996bda1861a
3
+ size 411402
models/model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:46eee60a5eac1402f8402ce1915230e6ca75d8d05c35c4e9500eadf2e39c525a
3
+ size 47062827
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastai
2
+ pandas
3
+ scikit-learn