Senasu commited on
Commit
07b04a1
·
verified ·
1 Parent(s): f9b3a7d

Uploaded Main Files

Browse files
Files changed (4) hide show
  1. app.py +96 -0
  2. logistic_regression_model.pkl +3 -0
  3. requirements.txt +4 -0
  4. vectorizer.pkl +3 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ def stress_prediction(text):
10
+ text_arr = [text]
11
+ text_transformed = vect.transform(text_arr)
12
+ prediction = model.predict(text_transformed)
13
+ return prediction
14
+
15
+ # Main function to render the Streamlit app
16
+ def main():
17
+ # Set page configuration with a fancy icon and layout
18
+ st.set_page_config(page_title="Stress Prediction", page_icon="🧠", layout="centered")
19
+
20
+ # Add custom CSS for styling
21
+ st.markdown("""
22
+ <style>
23
+ .main {
24
+ background-color: #F0F8FF;
25
+ border-radius: 10px;
26
+ padding: 20px;
27
+ font-family: Arial, sans-serif;
28
+ }
29
+ .title {
30
+ font-size: 2rem;
31
+ font-weight: bold;
32
+ color: #0078d4;
33
+ }
34
+ .text-area {
35
+ background-color: #FFFFFF;
36
+ border-radius: 10px;
37
+ padding: 10px;
38
+ font-size: 1.1rem;
39
+ }
40
+ .button {
41
+ background-color: #0078d4;
42
+ color: white;
43
+ font-size: 1.2rem;
44
+ border-radius: 10px;
45
+ padding: 10px 20px;
46
+ }
47
+ .result {
48
+ font-size: 1.5rem;
49
+ color: #FF6347;
50
+ font-weight: bold;
51
+ }
52
+ .explanation {
53
+ font-size: 1.1rem;
54
+ color: #808080;
55
+ margin-top: 10px;
56
+ }
57
+ </style>
58
+ """, unsafe_allow_html=True)
59
+
60
+ # Sidebar for additional information
61
+ st.sidebar.title("About")
62
+ st.sidebar.write("""
63
+ This application predicts whether you are feeling stressed based on the text you input.
64
+ Just type how you're feeling, and the model will classify it for you.
65
+ Let's see if you're under pressure!
66
+ """)
67
+
68
+ # App title and description
69
+ st.markdown('<div class="title">Stress Prediction</div>', unsafe_allow_html=True)
70
+ st.write("""
71
+ Enter your mental state below, and we will predict if you're under stress or not.
72
+ """)
73
+
74
+ # Input text area
75
+ text = st.text_area("Type your feelings", "", height=150, key="text_input", label_visibility="visible")
76
+
77
+ # Prediction button
78
+ if st.button("Predict Stress", key="predict_button", help="Click to predict stress level", use_container_width=True):
79
+ if text.strip() == "":
80
+ st.warning("Please enter some text to make a prediction!")
81
+ else:
82
+ # Predict stress
83
+ stress_pred = stress_prediction(text)
84
+
85
+ # Display the result with enhanced visualization
86
+ st.markdown(f'<div class="result">Prediction: {"Stressed" if stress_pred[0] == "Stress" else "Not Stressed"}</div>', unsafe_allow_html=True)
87
+
88
+ # Add explanation text
89
+ st.markdown('<div class="explanation">Our model analyzed your feelings and predicted your stress level based on your input.</div>', unsafe_allow_html=True)
90
+
91
+ # Show confidence score (fake example here, can be modified if model returns probability)
92
+ confidence = np.random.uniform(0.75, 0.95) # Fake confidence score, replace with actual model confidence if available
93
+ st.markdown(f'<div class="explanation">Confidence: {confidence:.2f}</div>', unsafe_allow_html=True)
94
+
95
+ if __name__ == "__main__":
96
+ main()
logistic_regression_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c7d052841a5aab85fe0ce9c5f68c0e70209c73460feb727d2e807f7036247f30
3
+ size 592495
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ joblib
3
+ scikit-learn
4
+ nltk
vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:220bad2fa4c82d68d940e9c16ca8d4225f348536b0f366ed683424cb72936219
3
+ size 1243919