File size: 2,034 Bytes
127c3c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pandas as pd
from tensorflow.keras.models import load_model
import streamlit as st

model = load_model('/Users/wismaeka/Documents/ds/p2-ftds033-rmt-g7-wismaeka')


def run():
    st.title('How are you feeling today?')
    st.write('This is a simple web app to predict sentiment of a text using deep learning. Input your feeling below to get the prediction.')
    st.write('Trust me, I have analyzed it for you!')

    text = st.text_input('Text', 'I feel so sad today')

    def convert_to_label(pred):
        if pred == 0:
            return 'Normal'
        elif pred == 1:
            return 'Suicidal'
        elif pred == 2:
            return 'Anxiety'
        elif pred == 3:
            return 'Depression'
        elif pred == 4:
            return 'Stress'
        elif pred == 5:
            return 'Bipolar'
        elif pred == 6:
            return 'Personality Disorder'
        else:
            return 'Unknown'

    if st.button("Predict Your Feeling"):
        prediction = model.predict(text)
        label = convert_to_label(prediction)
        if label == 'Normal':
            st.success('Hi! Keep up the good work! You are feeling Okay today.')
        elif label == 'Suicidal':
            st.error('Hi! I detect you are feeling Suicidal. Please seek help.')
        elif label == 'Anxiety':
            st.error('Hi! I detect you are feeling Anxious. You may want to talk to someone.')
        elif label == 'Depression':
            st.error('Hi! I detect you are feeling Depressed. Please seek help.')
        elif label == 'Stress':
            st.error('Hi! I detect you are feeling Stressed. Please take a break.')
        elif label == 'Bipolar':
            st.error('Hi! I detect you are feeling Bipolar. Please seek help.')
        elif label == 'Personality Disorder':
            st.error('Hi! I detect you are having Personality Disorder. Please seek help.')
        else:
            st.error('Hi! I cannot detect your feeling. Please try again.')


if __name__ == '__main__':
    run()