-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
78 lines (66 loc) · 2.33 KB
/
app.py
File metadata and controls
78 lines (66 loc) · 2.33 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pandas as pd
from spacy.lang.en.stop_words import STOP_WORDS
from flask import Flask, request, jsonify, render_template
# import nltk
from keras.models import load_model
# from tenacity import retry
# from tensorflow.keras.preprocessing.text import Tokenizer
# from nltk.corpus import stopwords
# from nltk.stem import PorterStemmer
# import numpy as np
import os
from process import pre_process, pro
model= load_model("model_lstm.h5")
# import numpy as np
# import spacy
# from sklearn.svm import LinearSVC
# from sklearn.feature_extraction.text import TfidfVectorizer
# from sklearn.pipeline import Pipeline
# import joblib
# import string
# from tokenizer import tokenizee
# We have loaded the modek
# os.chdir(r'C:\Users\utkar\Desktop\Hate speech\Twitter_kagle')
# model = load_model("network_lstm.h5")
# model = load_model("C:\Users\utkar\Desktop\Hate speech\Twitter_kagle\model_lstm.h5")
# Now we have to process the given input and predict it using the trained model
# model_load.predict(X_val)
stopwords = list(STOP_WORDS)
# Create the app object
app = Flask(__name__)
# Define predict function
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predict/',methods=['POST','GET'])
def predict():
if request.method == 'POST':
text = request.form['tweet']
# def pre_process(text):
# return pro(text)
lis = pre_process(text)
pred = model.predict(lis)
a = pred[0][0]
b = pred[0][1]
c = pred[0][2]
mx = 0
if a>b and a>c:
mx = a
elif b>a and b>c:
mx = b
elif c>a and c>b:
mx = c
# mx = max(pred[0][0],pred[0][1],pred[0][2])
# 1 positive 2 negative 0 neutral
if (mx==b):
return render_template('index.html', prediction_textb='Positive'+' '+str(b))
elif (mx==a):
return render_template('index.html', prediction_texta='Neutral'+' '+str(a))
elif (mx==c):
return render_template('index.html', prediction_textc='Negative'+' '+str(c))
# else:
# return render_template('index.html', prediction_text='Cannot classify'+' '+str(a) +' '+str(b) +' '+str(c))
# else:
# return render_template('index.html')
if __name__ == "__main__":
app.run(debug=True)