CoolFace
Apppublic

Tochile/offensive

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py57 linesDownload Raw Back to root
1from flask import Flask, render_template, url_for, request2from flask_bootstrap import Bootstrap3import pickle4import pandas as pd5import numpy as np6from sklearn.feature_extraction.text import CountVectorizer7from sklearn.feature_extraction.text import TfidfVectorizer8import joblib9 10app = Flask(__name__)11Bootstrap(app)12 13 14@app.route('/')15def home():16	return render_template("home.html")17 18@app.route('/predict', methods = ['POST'])19def predict():20	#return render_template("result.html")21	22 23	df= pd.read_csv("data2.csv")24 25	df_data = df[["class", "comments"]]26	df_x = df_data["comments"]27	df_y = df_data["class"]28 29	corpus = df_x30	cv = CountVectorizer()31	X = cv.fit_transform(corpus)32 33	from sklearn.model_selection import train_test_split34	X_train, X_test, y_train, y_test = train_test_split(X, df_y, test_size=0.3, random_state=42)35 36	from sklearn.linear_model import LogisticRegression37	clf = LogisticRegression()38	clf.fit(X_train, y_train)39	clf.score(X_test, y_test)40 41	# # #load the vectorizer42	# my_vectorizer = open("comment_vectorizer.pkl", "rb")43	# vector = joblib.load(my_vectorizer)44	# #load the model45	# my_model = open("myFinalModel.pkl","rb")46	# model_clf = joblib.load(my_model)47 48 49	if request.method == 'POST':50		comment = request.form['comment']51		data = [comment]52		vect = cv.transform(data).toarray()53		my_prediction = clf.predict(vect)54	return render_template('home.html', name = data, prediction = my_prediction, user_comment = comment)55 56if __name__ == '__main__':57	app.run(debug = True)