|
import streamlit as stl |
|
import numpy as np |
|
import pandas as pd |
|
from sklearn.feature_extraction.text import CountVectorizer |
|
from sklearn.pipeline import Pipeline |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.naive_bayes import MultinomialNB |
|
from sklearn.metrics import accuracy_score |
|
stl.write('this is sentiment analysis') |
|
df = pd.read_csv(r'combined_emotion.csv') |
|
model1 = Pipeline([("Feature_Engineer",CountVectorizer(binary= True,stop_words = 'english')), |
|
("Algorithm", MultinomialNB())]) |
|
X = df['sentence'] |
|
y = df['emotion'] |
|
|
|
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.3,random_state=23) |
|
model1.fit(x_train,y_train) |
|
y_pred = model1.predict(x_test) |
|
if stl.button('click for accuracy'): |
|
stl.write(accuracy_score(y_test,y_pred)) |
|
str = stl.text_input('enter text') |
|
if stl.button('click to check'): |
|
if model1.predict([str]) == 'sad': |
|
stl.write('sad βΉοΈ') |
|
elif model1.predict([str]) == 'angry': |
|
stl.write('anger π‘') |
|
elif model1.predict([str]) == 'fear': |
|
stl.write('fear π¨') |
|
elif model1.predict([str]) == 'joy': |
|
stl.write('joy π') |
|
elif model1.predict([str]) == 'love': |
|
stl.write('π') |
|
else : |
|
stl.write('surprise π²') |