-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairbnb_ratings_app.py
39 lines (30 loc) · 1.42 KB
/
airbnb_ratings_app.py
1
2
3
4
5
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
from flask import Flask, request, render_template, jsonify, request, abort
from airbnb_ratings_api import predict_ratings
app = Flask(__name__)
amenities = ['24-hour check-in', 'Air conditioning', 'BBQ grill', 'Bed linens',
'Cable TV', 'Coffee maker', 'Dishwasher', 'Elevator',
'Extra pillows and blankets', 'Family/kid friendly',
'Fire extinguisher', 'First aid kit', 'Gym', 'Indoor fireplace',
'Internet', 'Keypad', 'Lock on bedroom door', 'Lockbox',
'Long term stays allowed', 'Luggage dropoff allowed',
'Pack ’n Play/travel crib', 'Patio or balcony', 'Pets allowed',
'Private entrance', 'Private living room', 'Refrigerator',
'Safety card', 'Self check-in']
@app.route("/predict", methods=['POST'])
def make_prediction():
if not request.json:
abort(400)
data = request.json
response = predict_ratings(data)
return jsonify(response)
# return render_template("result.html", response=jsonify(response))
@app.route("/")
def front():
return render_template("front.html")
@app.route("/rate")
def index():
amenity_list = [{'id': amenity.replace(' ', '_').replace('-', '_').replace('/', '_'),
'label': amenity} for amenity in amenities]
return render_template("index.html", amenities=amenity_list)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=False)