-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·79 lines (70 loc) · 3.6 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from regressor import Regressor
from codecs import open
import time
from flask import Flask, render_template, request
app = Flask(__name__)
print("Load regressor")
start_time = time.time()
regressor = Regressor()
print("Regressor is successfully loaded")
print(time.time() - start_time, "seconds")
@app.route("/", methods = ["GET"])
def index_page():
return render_template('index.html')
@app.route("/predict-hata-price", methods = ["POST", "GET"])
def predict_page(host_is_superhost = False,
host_has_profile_pic = False, host_identity_verified = False,
require_guest_profile_picture = False,
require_guest_phone_verification = False,
latitude = 51.5423, longitude = -0.1285, accommodates = "",
bathrooms = "", bedrooms = "", beds = "",
square_feet = "", security_deposit = "", cleaning_fee = "",
guests_included = "", extra_people = "", minimum_nights = "",
predicted_price = ""):
if request.method == "POST":
host_is_superhost = int(bool(request.form.get("host_is_superhost")))
host_has_profile_pic = int(bool(request.form.get("host_has_profile_pic")))
host_identity_verified = int(bool(request.form.get("host_identity_verified")))
require_guest_profile_picture = int(bool(request.form.get("require_guest_profile_picture")))
require_guest_phone_verification = int(bool(request.form.get("require_guest_phone_verification")))
latitude = float(request.form.get("latitude"))
longitude = float(request.form.get("longitude"))
accommodates = int(request.form.get("accommodates"))
bathrooms = int(request.form.get("bathrooms"))
bedrooms = int(request.form.get("bedrooms"))
beds = int(request.form.get("beds"))
square_feet = int(request.form.get("square_feet"))
security_deposit = int(request.form.get("security_deposit"))
cleaning_fee = int(request.form.get("cleaning_fee"))
guests_included = int(request.form.get("guests_included"))
extra_people = int(request.form.get("extra_people"))
minimum_nights = int(request.form.get("minimum_nights"))
logfile = open("hata_otsenyator_logs.txt", "ab", "utf-8")
logfile.write("<response>\n")
predicted_price = regressor.predict_price(
[[host_is_superhost, host_has_profile_pic,
host_identity_verified, 1, # consider location is always exact
require_guest_profile_picture, require_guest_phone_verification,
latitude, longitude, accommodates, bathrooms,
bedrooms, beds,
square_feet, security_deposit, cleaning_fee,
guests_included, extra_people, minimum_nights]]
)
logfile.write(str(predicted_price))
logfile.write("<response>\n")
logfile.close()
time.sleep(3)
return render_template('simple_page.html',
host_is_superhost = host_is_superhost,
host_has_profile_pic = host_has_profile_pic,
host_identity_verified = host_identity_verified,
require_guest_profile_picture = require_guest_profile_picture,
require_guest_phone_verification = require_guest_phone_verification,
latitude = latitude, longitude = longitude, accommodates = accommodates,
bathrooms = bathrooms, bedrooms = bedrooms, beds = beds, square_feet = square_feet,
security_deposit = security_deposit, cleaning_fee = cleaning_fee,
guests_included = guests_included, extra_people = extra_people,
minimum_nights = minimum_nights,
predicted_price = predicted_price)
if __name__ == "__main__":
app.run(host = '0.0.0.0', port = 44445, debug = True)