Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +22 -15
- model.h5 +2 -2
- requirements.txt +5 -3
app.py
CHANGED
|
@@ -1,20 +1,27 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import numpy as np
|
| 3 |
from sklearn.feature_extraction.text import CountVectorizer
|
|
|
|
|
|
|
| 4 |
from tensorflow.keras.models import load_model
|
|
|
|
|
|
|
| 5 |
|
| 6 |
model=load_model("model.h5")
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
if
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
model.h5
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:732d0fa8473925ef2a813886b6570cc0e9fc8b0d03fa1319573150c09a86a83a
|
| 3 |
+
size 17102424
|
requirements.txt
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
-
scikit-learn
|
| 2 |
-
numpy
|
| 3 |
streamlit
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
streamlit
|
| 2 |
+
scikit-learn
|
| 3 |
+
textblob
|
| 4 |
+
tensorflow
|
| 5 |
+
nltk
|
| 6 |
+
numpy
|