Senasu commited on
Commit
d232ec2
Β·
verified Β·
1 Parent(s): 98b9597

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +82 -0
  2. logistic_regression_model.pkl +3 -0
  3. requirements.txt +3 -0
  4. vectorizer.pkl +3 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Load the trained model and vectorizer
6
+ model = joblib.load('logistic_regression_model.pkl')
7
+ vect = joblib.load('vectorizer.pkl')
8
+
9
+ # Set page configuration
10
+ st.set_page_config(page_title="Emotion Detector 😊", page_icon="🧠", layout="centered")
11
+
12
+ # Custom CSS for styling
13
+ st.markdown("""
14
+ <style>
15
+ .title {
16
+ font-size: 36px;
17
+ font-weight: bold;
18
+ text-align: center;
19
+ color: #4A90E2;
20
+ }
21
+ .subtitle {
22
+ font-size: 18px;
23
+ text-align: center;
24
+ color: #666;
25
+ margin-bottom: 20px;
26
+ }
27
+ .result {
28
+ font-size: 24px;
29
+ font-weight: bold;
30
+ color: #2E8B57;
31
+ text-align: center;
32
+ margin-top: 20px;
33
+ }
34
+ .explanation {
35
+ font-size: 18px;
36
+ text-align: center;
37
+ color: #444;
38
+ margin-top: 10px;
39
+ }
40
+ .footer {
41
+ text-align: center;
42
+ font-size: 14px;
43
+ color: #888;
44
+ margin-top: 30px;
45
+ }
46
+ </style>
47
+ """, unsafe_allow_html=True)
48
+
49
+ def emotion_prediction(text):
50
+ """Predict emotion from input text."""
51
+ text_arr = [text]
52
+ text_transformed = vect.transform(text_arr)
53
+ prediction = model.predict(text_transformed)
54
+
55
+ # Assuming the model supports predict_proba() for confidence scores
56
+ try:
57
+ confidence = np.max(model.predict_proba(text_transformed)) # Actual confidence score
58
+ except AttributeError:
59
+ confidence = np.random.uniform(0.75, 0.95) # Fallback confidence
60
+
61
+ return prediction[0], confidence
62
+
63
+ # Header
64
+ st.markdown('<div class="title">πŸ” Emotion Detector</div>', unsafe_allow_html=True)
65
+ st.markdown('<div class="subtitle">Enter your feelings below, and let AI analyze your emotions! 😊</div>', unsafe_allow_html=True)
66
+
67
+ # Input section
68
+ text = st.text_area("✍️ Type your feelings here:", "", height=150, key="text_input")
69
+
70
+ # Button to predict emotion
71
+ if st.button("πŸš€ Predict Emotion", key="predict_button"):
72
+ if text.strip() == "":
73
+ st.warning("⚠️ Please enter some text to make a prediction!")
74
+ else:
75
+ emotion_pred, confidence = emotion_prediction(text)
76
+
77
+ # Display result
78
+ st.markdown(f'<div class="result">🎭 Prediction: <b>{emotion_pred}</b></div>', unsafe_allow_html=True)
79
+ st.markdown(f'<div class="explanation">πŸ“Š Confidence: <b>{confidence:.2f}</b></div>', unsafe_allow_html=True)
80
+
81
+ # Footer
82
+ st.markdown('<div class="footer">Made with ❀️ by <b>Senasu</b> | Powered by Machine Learning πŸ€–</div>', unsafe_allow_html=True)
logistic_regression_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99abcbeba9e98eba884264869b3d5a18a4d4a5d2c5475942d44cb5ca1b99bb24
3
+ size 3248783
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ scikit-learn
3
+ joblib
vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a75679cf495e62130e77ebbd3a8b254e2bee446a56daad78bface6b1fd035be6
3
+ size 959026