File size: 1,295 Bytes
966a632
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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 😲')