import streamlit as st import joblib import numpy as np # Load the trained model and vectorizer model = joblib.load('logistic_regression_model.pkl') vect = joblib.load('vectorizer.pkl') def stress_prediction(text): text_arr = [text] text_transformed = vect.transform(text_arr) prediction = model.predict(text_transformed) return prediction # Main function to render the Streamlit app def main(): # Set page configuration with a fancy icon and layout st.set_page_config(page_title="Stress Prediction", page_icon="🧠", layout="centered") # Add custom CSS for styling st.markdown(""" """, unsafe_allow_html=True) # Sidebar for additional information st.sidebar.title("About") st.sidebar.write(""" This application predicts whether you are feeling stressed based on the text you input. Just type how you're feeling, and the model will classify it for you. Let's see if you're under pressure! """) # App title and description st.markdown('
Stress Prediction
', unsafe_allow_html=True) st.write(""" Enter your mental state below, and we will predict if you're under stress or not. """) # Input text area text = st.text_area("Type your feelings", "", height=150, key="text_input", label_visibility="visible") # Prediction button if st.button("Predict Stress", key="predict_button", help="Click to predict stress level", use_container_width=True): if text.strip() == "": st.warning("Please enter some text to make a prediction!") else: # Predict stress stress_pred = stress_prediction(text) # Display the result with enhanced visualization st.markdown(f'
Prediction: {"Stressed" if stress_pred[0] == "Stress" else "Not Stressed"}
', unsafe_allow_html=True) # Add explanation text st.markdown('
Our model analyzed your feelings and predicted your stress level based on your input.
', unsafe_allow_html=True) # Show confidence score (fake example here, can be modified if model returns probability) confidence = np.random.uniform(0.75, 0.95) # Fake confidence score, replace with actual model confidence if available st.markdown(f'
Confidence: {confidence:.2f}
', unsafe_allow_html=True) if __name__ == "__main__": main()