-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (33 loc) · 1 KB
/
Copy pathapp.py
File metadata and controls
40 lines (33 loc) · 1 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
import streamlit as st
import joblib
import os
model = joblib.load("emotion_model_logistic.pkl")
emotion_labels = {
0: "Sad",
1: "Happy",
2: "Love",
3: "Angry",
4: "Fear"
}
gif_paths = {
"Sad": "image/Sad.gif",
"Happy": "image/Happy.gif",
"Love": "image/Love.gif",
"Angry": "image/Anger.gif",
"Fear": "image/fear.gif"
}
st.title("Emotion Detection from Text")
st.write("Enter a sentence and the model will detect the emotion.")
user_input = st.text_area("Enter your text:", "")
if st.button("Analyze Emotion"):
if user_input.strip():
prediction = model.predict([user_input])[0]
emotion = emotion_labels.get(prediction, "Unknown Emotion")
st.write(f"### Emotion Detected: **{emotion}**")
gif_path = gif_paths.get(emotion)
if gif_path and os.path.exists(gif_path):
st.image(gif_path)
else:
st.warning("GIF not found for this emotion.")
else:
st.warning("Please enter some text to analyze.")