-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.py
45 lines (37 loc) · 1.24 KB
/
start.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
import pickle
import numpy as np
from flask import Flask, request, jsonify, redirect, url_for, abort, render_template
from sklearn import datasets
from flask_wtf import FlaskForm
from wtforms import StringField
from wtforms.validators import DataRequired
from catboost import CatBoostRegressor
import predict
app = Flask(__name__)
app.config.update(dict(
SECRET_KEY="powerful secretkey",
WTF_CSRF_SECRET_KEY="a csrf secret key"
))
class MyForm(FlaskForm):
name = StringField('your password', validators=[DataRequired()])
@app.route('/', methods=('GET', 'POST'))
def submit():
form = MyForm()
try:
if request.method == 'POST':
password = request.form['password']
if password =='':
abort(400)
model = pickle.load(open('model', 'rb'))
prediction = predict.predict(password, model)
img = 'static/'
if prediction > 50:
img += 'lol.png'
else:
img += 'not-bad.jpg'
return render_template('submit.html', \
form=form, prediction=prediction, img=img)
#return form.data['name']
return render_template('submit.html', form=form)
except Exception:
abort(400)