Upload New File

parent aa2a87e7
from flask import Flask, render_template, Response, request
from flask_cors import CORS
import requests as r
import pickle
import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder
app = Flask(__name__)
CORS(app)
lr_model = pickle.load(open('trained_models/finalized_model_lr.sav', 'rb'))
final_result_list = [0, 0, 0, 0, 0]
@app.route('/')
def home():
return render_template('index.html')
@app.route('/classification', methods=['POST'])
def classification():
global emotion_data
question_no = request.form['question_no']
answer = request.form['answer']
emotion = request.form['emotion']
add_status = request.form['add_status']
features = data_preprocessing([question_no, answer, emotion])
print(features)
prediction = lr_model.predict(features)
if prediction[0] == 1:
final_result_list[0] += 1
elif prediction[0] == 2:
final_result_list[1] += 1
elif prediction[0] == 3:
final_result_list[2] += 1
elif prediction[0] == 4:
final_result_list[3] += 1
else:
final_result_list[4] += 1
if add_status == 'add':
return render_template('index.html')
else:
return render_template('result_2.html', data=final_result_list)
def data_preprocessing(data):
df = pd.read_csv('data/reason_data_up.csv')
# df.loc[len(df.index)] = data
df.append(pd.Series(data, index=df.columns[:len(data)]), ignore_index=True)
df['question no'] = df['question no'].astype('str')
df['answer'] = df['answer'].astype('str')
df['emotion'] = df['emotion'].astype('str')
df[['question no', 'answer', 'emotion']] = df[['question no','answer','emotion']].apply(LabelEncoder().fit_transform)
X_var = np.asarray(df[['question no', 'answer', 'emotion']])
return [X_var[-1]]
if __name__ == "__main__":
app.run(debug=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment