-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
46 lines (35 loc) · 1.2 KB
/
app.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
46
# Library imports
import pandas as pd
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 spacy.lang.en.stop_words import STOP_WORDS
from flask import Flask, request, jsonify, render_template
import nltk
# Load trained Pipeline
model = joblib.load('sentiment_model.pkl')
stopwords = list(STOP_WORDS)
# Create the app object
app = Flask(__name__)
# creating a function for data cleaning
from custom_tokenizer_function import CustomTokenizer
# Define predict function
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
new_review = [str(x) for x in request.form.values()]
# data = pd.DataFrame(new_review)
# data.columns = ['new_review']
predictions = model.predict(new_review)[0]
if predictions==0:
return render_template('index.html', prediction_text='Negative')
else:
return render_template('index.html', prediction_text='Positive')
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=5000)