-
Notifications
You must be signed in to change notification settings - Fork 53
/
app2.py
46 lines (35 loc) · 1.2 KB
/
app2.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
import os, sys, shutil, time
from flask import Flask, request, jsonify, render_template
import pandas as pd
from sklearn.externals import joblib
from sklearn.ensemble import RandomForestClassifier
import numpy as np
import urllib.request
import json
from geopy.geocoders import Nominatim
endpoint='https://maps.googleapis.com/maps/api/geocode/json?address='
key='AIzaSyDM8KzL_AFUOA9lfK7ZAFCo3I74k63jG24'
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods = ['POST'])
def predict():
rfc = joblib.load('model/rf_model')
print('model loaded')
if request.method == 'POST':
address = request.form['Location']
geolocator = Nominatim()
location = geolocator.geocode(address)
print(location.address)
lat=[location.latitude]
log=[location.longitude]
latlong=pd.DataFrame({'latitude':lat,'longitude':log})
print(latlong)
DT= request.form['timestamp']
latlong['timestamp']=DT
data=latlong
my_prediction = rfc.predict(data)
return render_template('result.html', prediction = my_prediction)
if __name__ == '__main__':
app.run(debug = True)