-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
41 lines (27 loc) · 1.06 KB
/
app.py
File metadata and controls
41 lines (27 loc) · 1.06 KB
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
35
36
37
38
39
40
41
import streamlit as st
import joblib
model = joblib.load("models/sentiment_svc_model.pkl")
vectorizer = joblib.load("models/tfidf_vectorizer.pkl")
st.title("Text Emotion Predication")
st.write("Enter a sentence and the model will predict the emotion.")
user_input = st.text_area("Enter text here:")
if st.button("Predict Emotion"):
if user_input.strip() != "":
# Vectorize input
input_vec = vectorizer.transform([user_input])
d = {'sadness': 0, 'anger': 1, 'love': 2, 'surprise': 3, 'fear': 4, 'joy': 5}
reverse_d = {v:k for k,v in d.items()}
emotion_emojis = {
"sadness": "😢",
"joy": "😊",
"anger": "😠",
"fear": "😨",
"love": "❤️",
"surprise": "😲"
}
# Predict emotion
prediction_num = model.predict(input_vec)[0]
prediction = reverse_d[prediction_num]
st.success(f"Emotion: {prediction} {emotion_emojis.get(prediction,'')}")
else:
st.warning("Please enter some text.")