-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
44 lines (35 loc) · 1.07 KB
/
Copy pathapp.py
File metadata and controls
44 lines (35 loc) · 1.07 KB
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
# Written by Kanchi Tank
from flask_bootstrap import Bootstrap
from flask import Flask, request, render_template, url_for
import numpy as np
import pandas as pd
# Import Packages
import joblib
from sklearn.feature_extraction.text import CountVectorizer
gender_app = Flask(__name__)
Bootstrap(gender_app)
@gender_app.route('/')
def index():
return render_template('index.html')
@gender_app.route('/predict', methods=['POST'])
def predict():
df = pd.read_csv("data/Names_dataset.csv")
# Features and Labels
x_df = df.name
y_df = df.gender
# Vectorization
corpus = x_df.values.astype('U')
cv = CountVectorizer()
X = cv.fit_transform(corpus)
# Loading the ML Model
nb = open("models/naivebayes.pkl","rb")
clf_1 = joblib.load(nb)
# Receive the input
if request.method == 'POST':
name_query = request.form['name_query']
data = [name_query]
vct = cv.transform(data).toarray()
my_prediction = clf_1.predict(vct)
return render_template('results.html', prediction = my_prediction, name = name_query.upper())
if __name__ == '__main__':
gender_app.run(debug=True)