File size: 2,098 Bytes
291793f
 
c12c8cd
29448e1
a681e0a
26f04af
0d00d6d
 
 
29448e1
 
 
 
 
4d1b284
29448e1
 
 
 
 
 
 
 
 
3f7ec6a
 
 
0d00d6d
 
3f7ec6a
 
 
 
 
 
0d00d6d
3f7ec6a
 
0d00d6d
 
a681e0a
 
 
 
 
ff694a9
a681e0a
c33cdf2
 
a681e0a
c33cdf2
 
 
 
 
 
 
 
 
 
 
 
 
807d96d
c33cdf2
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
57
58
59
60
61
62
63
64
65
66
# Use a pipeline as a high-level helper
from transformers import pipeline
import streamlit as st
import streamlit.components.v1 as components

pipe_1 = pipeline("text-classification", model="mavinsao/mi-roberta-mental-finetuned")
pipe_2 = pipeline("text-classification", model="mavinsao/roberta-mental-finetuned")


# Streamlit app with background image
def st_display_background(image_url):
    st_style = f"""
            <style>
            body {{
                background-image: url("{image_url}") !important;
                background-size: cover;
            }}
            </style>
            """
    st.markdown(st_style, unsafe_allow_html=True)

image_url = "https://images.unsplash.com/photo-1504701954957-2010ec3bcec1?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"


def ensemble_predict(text): 
    # Store results from each model
    results_1 = pipe_1(text)    
    results_2 = pipe_2(text)

    ensemble_scores = {} 
    for results in [results_1, results_2]:  # Iterate through predictions
        for result in results:
            label = result['label']
            score = result['score']
            ensemble_scores[label] = ensemble_scores.get(label, 0) + score / 2  

    predicted_label = max(ensemble_scores, key=ensemble_scores.get) 
    confidence = ensemble_scores[predicted_label]  # Ensemble confidence

    return predicted_label, confidence

# Streamlit app
st.title('Mental Illness Prediction')

# Input text area for user input
sentence = st.text_area("Enter the long sentence to predict your mental illness state:")

st_display_background(image_url)

if st.button('Predict'):
  # ... (input validation ... )
  predicted_label, confidence = ensemble_predict(sentence)

  # CSS injection to target the labels
  st.markdown("""
  <style>
     div[data-testid="metric-container"]  {
        font-weight: bold;
        font-size: 18px; /* Adjust the font size as desired */
     }
  </style>
  """, unsafe_allow_html=True)  

  st.write("Result:", predicted_label)
  st.write("Confidence:", confidence)