sad-app / app.py
Srinivas T B
app
408fb7d verified
raw
history blame
2.67 kB
import streamlit as st
import numpy as np
# Custom CSS for styling
st.markdown(
"""
<style>
.header-text {
color: #333333;
text-align: center;
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
}
.result-text {
color: #333333;
font-size: 18px;
margin-bottom: 10px;
}
</style>
""",
unsafe_allow_html=True
)
def map_to_emotion(spo2, bp, temp):
# Spo2 mapping
if spo2 >= 96:
spo2_emotion = ["Joy", "Anticipation", "Trust"]
elif spo2 == 93 or spo2 == 94:
spo2_emotion = ["Fear"]
else:
spo2_emotion = ["Anger", "Disgust"]
# BP mapping
if bp == "110/70mmHg":
bp_emotion = ["Trust"]
elif bp == "122/74 mmHg":
bp_emotion = ["Joy"]
else:
bp_emotion = ["Surprise"]
# Temperature mapping
if temp >= 98.7 and temp <= 99.1:
temp_emotion = ["Joy", "Surprise", "Disgust", "Anticipation"]
elif temp < 98.7:
temp_emotion = ["Sadness"]
else:
temp_emotion = ["Fear", "Anger"]
# Combine all emotions
emotions = spo2_emotion + bp_emotion + temp_emotion
return emotions
def predict_levels(emotions):
# Placeholder for machine learning models
# Here, we generate random predictions as placeholders
stress_percentage = np.random.randint(0, 100)
anxiety_percentage = np.random.randint(0, 100)
depression_percentage = np.random.randint(0, 100)
return stress_percentage, anxiety_percentage, depression_percentage
def main():
st.title("Emotion Analysis and Mental Health Prediction")
st.markdown("### Enter Vital Parameters:")
# User inputs
spo2 = st.selectbox("Select Spo2 Level", ["96% or more", "93-94%", "92% or less"])
bp = st.selectbox("Select Blood Pressure Level", ["110/70mmHg", "122/74 mmHg", "Others"])
temp = st.selectbox("Select Body Temperature", ["98.7F-99.1F", "Less than 98.7F", "Greater than 99.1F"])
# Map inputs to emotions
emotions = map_to_emotion(spo2, bp, temp)
st.markdown("### Emotion Analysis Results:")
for emotion in emotions:
st.write(f"- {emotion}")
# Predict levels using machine learning models
st.markdown("### Predicted Mental Health Levels:")
stress_percentage, anxiety_percentage, depression_percentage = predict_levels(emotions)
st.write(f"Stress Percentage (approx): {stress_percentage}%")
st.write(f"Anxiety Percentage (approx): {anxiety_percentage}%")
st.write(f"Depression Percentage (approx): {depression_percentage}%")
if __name__ == "__main__":
main()