-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.py
34 lines (31 loc) · 1.12 KB
/
webapp.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
from flask import Flask, render_template, url_for, request
import pandas as pd
import pickle
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.externals import joblib
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import train_test_split
app = Flask(__name__)
@app.route("/")
def home():
return render_template("home.html")
@app.route("/predict",methods=["POST"])
def predict():
df= pd.read_csv("YoutubeSpamData.csv")
df_data = df[["CONTENT","CLASS"]]
df_x = df_data['CONTENT']
df_y = df_data.CLASS
cv = CountVectorizer()
X = cv.fit_transform(df_x)
X_train, X_test, y_train, y_test = train_test_split(X, df_y, test_size=0.33, random_state=42)
clf = MultinomialNB() # Naive Bayes classifier
clf.fit(X_train,y_train)
clf.score(X_test,y_test)
if request.method == 'POST':
comment = request.form['comment']
data = [comment]
vect = cv.transform(data).toarray()
my_prediction = clf.predict(vect)
return render_template('result.html',prediction = my_prediction)
if __name__ == "__main__":
app.run(debug=True)