prahalya commited on
Commit
2e6c27d
Β·
verified Β·
1 Parent(s): 4103f61

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +80 -0
  2. inno.jpg +0 -0
  3. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
+
5
+ # Load pre-trained emotion detection model
6
+ model_name = "j-hartmann/emotion-english-distilroberta-base"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
+
10
+ # Get the actual emotion labels from the model
11
+ emotion_labels = model.config.id2label
12
+
13
+ # Emotion styles (emoji + colors)
14
+ emotion_styles = {
15
+ "joy": {"emoji": "πŸ˜ƒ", "color": "#D3D3D3"},
16
+ "sadness": {"emoji": "😒", "color": "#3498BB"},
17
+ "anger": {"emoji": "😑", "color": "#FFDAA9"},
18
+ "fear": {"emoji": "😨", "color": "#FFFAAD"},
19
+ "surprise": {"emoji": "😲", "color": "#98CB98"},
20
+ "disgust": {"emoji": "🀒", "color": "#FFBFC1"},
21
+ "neutral": {"emoji": "😐", "color": "#E6E6FA"}
22
+ }
23
+
24
+ # Streamlit UI
25
+ st.set_page_config(page_title="Emotion Detection", layout="centered")
26
+
27
+ # 🎨 Change Background Color
28
+ st.markdown(
29
+ """
30
+ <style>
31
+ body {
32
+ background-color:#AFEEEE; /* Light Grayish Blue */
33
+ }
34
+ </style>
35
+ """,
36
+ unsafe_allow_html=True
37
+ )
38
+
39
+ # 🎯 Add Image at the Top
40
+ st.image("inno.jpg", use_container_width=True,width=300)
41
+
42
+ st.markdown("<h1 style='text-align: center; color: #7D3B98;'>Emotion Detection using ML</h1>", unsafe_allow_html=True)
43
+ st.markdown("<h3 style='text-align: left; color: #3498BB;'>πŸ“ Enter the text:</h3>", unsafe_allow_html=True)
44
+
45
+ # User Input
46
+ user_text = st.text_input("", placeholder="Type your text here...")
47
+
48
+ if st.button("Submit"):
49
+ if user_text:
50
+ # Tokenize input text
51
+ inputs = tokenizer(user_text, return_tensors="pt")
52
+
53
+ # Get model predictions
54
+ with torch.no_grad():
55
+
56
+
57
+
58
+ outputs = model(**inputs)
59
+
60
+ # Get the predicted emotion
61
+ scores = outputs.logits[0]
62
+ predicted_label_id = torch.argmax(scores).item()
63
+ predicted_emotion = emotion_labels[predicted_label_id].strip().lower()
64
+
65
+ # Get emoji & color
66
+ emotion_data = emotion_styles.get(predicted_emotion, {"emoji": "😐", "color": "#D3D3D3"})
67
+ emoji_display = emotion_data["emoji"]
68
+ text_color = emotion_data["color"]
69
+
70
+ # Display Results with Color
71
+ st.markdown(
72
+ f"""
73
+ <div style="text-align: center; padding: 10px; border-radius: 10px; background-color: {text_color}; color: black; font-size: 24px;">
74
+ <b>Detected Emotion:</b> {predicted_emotion.capitalize()} {emoji_display}
75
+ </div>
76
+ """,
77
+ unsafe_allow_html=True
78
+ )
79
+ else:
80
+ st.warning("Please enter some text!")
inno.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ pandas
2
+ numpy
3
+ nltk
4
+ scikit-learn
5
+ streamlit
6
+ joblib