DasariHarshitha commited on
Commit
a588fe4
Β·
verified Β·
1 Parent(s): f1cd49c

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +77 -0
  2. innomatics-footer-logo.webp +0 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "#E6E6FA"},
16
+ "sadness": {"emoji": "😒", "color": "#3498DB"},
17
+ "anger": {"emoji": "😑", "color": "#FFDAB9"},
18
+ "fear": {"emoji": "😨", "color": "#FFFACD"},
19
+ "surprise": {"emoji": "😲", "color": "#98FB98"},
20
+ "disgust": {"emoji": "🀒", "color": "#FFB6C1"},
21
+ "neutral": {"emoji": "😐", "color": "#D3D3D3"}
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("innomatics-footer-logo.webp", use_container_width=True,width=300)
41
+
42
+ st.markdown("<h1 style='text-align: center; color: #7D3C98;'>Emotion Detection using ML</h1>", unsafe_allow_html=True)
43
+ st.markdown("<h3 style='text-align: left; color: #3498DB;'>πŸ“ 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
+ outputs = model(**inputs)
56
+
57
+ # Get the predicted emotion
58
+ scores = outputs.logits[0]
59
+ predicted_label_id = torch.argmax(scores).item()
60
+ predicted_emotion = emotion_labels[predicted_label_id].strip().lower()
61
+
62
+ # Get emoji & color
63
+ emotion_data = emotion_styles.get(predicted_emotion, {"emoji": "😐", "color": "#D3D3D3"})
64
+ emoji_display = emotion_data["emoji"]
65
+ text_color = emotion_data["color"]
66
+
67
+ # Display Results with Color
68
+ st.markdown(
69
+ f"""
70
+ <div style="text-align: center; padding: 10px; border-radius: 10px; background-color: {text_color}; color: black; font-size: 24px;">
71
+ <b>Detected Emotion:</b> {predicted_emotion.capitalize()} {emoji_display}
72
+ </div>
73
+ """,
74
+ unsafe_allow_html=True
75
+ )
76
+ else:
77
+ st.warning("Please enter some text!")
innomatics-footer-logo.webp ADDED
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ transformer
3
+ torch