emirkaanozdemr commited on
Commit
5d9f15c
·
verified ·
1 Parent(s): 54f2de6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -26
app.py CHANGED
@@ -1,27 +1,28 @@
1
- import streamlit as st
2
- from sklearn.feature_extraction.text import CountVectorizer
3
- from textblob import TextBlob
4
- from nltk.stem import PorterStemmer
5
- from tensorflow.keras.models import load_model
6
- import numpy as np
7
- import nltk
8
-
9
- model=load_model("model.h5")
10
- pr=PorterStemmer()
11
- def lemmafn(text):
12
- words=TextBlob(text).words
13
- return [pr.stem(word) for word in words]
14
- vect=CountVectorizer(ngram_range=(1,4),max_features=100000,analyzer=lemmafn)
15
- st.title("Predicting Emotion of Text")
16
- text=st.text_area("Your text")
17
- if text is not None:
18
- text=text.lower()
19
- text=text.replace("[^\w\s]","")
20
- text=text.replace("\n","")
21
- text=text.replace("\d+","")
22
- text=vect.fit_transform([text])
23
- if st.button("Predict"):
24
- prediction=model.predict(text)
25
- class_names=["Joy","Love","Anger","Sadness","Fear","Surprise"]
26
- emotion=class_names[np.argmax(prediction)]
 
27
  st.write(emotion)
 
1
+ import streamlit as st
2
+ from sklearn.feature_extraction.text import CountVectorizer
3
+ from textblob import TextBlob
4
+ from nltk.stem import PorterStemmer
5
+ from tensorflow.keras.models import load_model
6
+ import numpy as np
7
+ import nltk
8
+ nltk.download("punkt")
9
+
10
+ model=load_model("model.h5")
11
+ pr=PorterStemmer()
12
+ def lemmafn(text):
13
+ words=TextBlob(text).words
14
+ return [pr.stem(word) for word in words]
15
+ vect=CountVectorizer(ngram_range=(1,4),max_features=100000,analyzer=lemmafn)
16
+ st.title("Predicting Emotion of Text")
17
+ text=st.text_area("Your text")
18
+ if text is not None:
19
+ text=text.lower()
20
+ text=text.replace("[^\w\s]","")
21
+ text=text.replace("\n","")
22
+ text=text.replace("\d+","")
23
+ text=vect.fit_transform([text])
24
+ if st.button("Predict"):
25
+ prediction=model.predict(text)
26
+ class_names=["Joy","Love","Anger","Sadness","Fear","Surprise"]
27
+ emotion=class_names[np.argmax(prediction)]
28
  st.write(emotion)