Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
text=text.
|
| 20 |
-
text=text.replace("\
|
| 21 |
-
text=text.replace("\
|
| 22 |
-
text=
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 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)
|