final
Browse files
app.py
CHANGED
@@ -1,13 +1,7 @@
|
|
1 |
-
|
2 |
-
from transformers import
|
3 |
-
import streamlit as st
|
4 |
|
5 |
-
|
6 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
7 |
-
|
8 |
-
# Load tokenizer and model
|
9 |
-
tokenizer = AutoTokenizer.from_pretrained("mavinsao/mi-roberta-classification")
|
10 |
-
model = AutoModelForSequenceClassification.from_pretrained("mavinsao/mi-roberta-classification").to(device)
|
11 |
|
12 |
# Streamlit app
|
13 |
st.title('Mental Illness Prediction')
|
@@ -17,17 +11,5 @@ sentence = st.text_area("Enter the long sentence to predict your mental illness
|
|
17 |
|
18 |
# Prediction button
|
19 |
if st.button('Predict'):
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
# Forward pass
|
24 |
-
with torch.no_grad():
|
25 |
-
outputs = model(**inputs)
|
26 |
-
|
27 |
-
# Get predicted probabilities
|
28 |
-
probabilities = torch.sigmoid(outputs.logits).squeeze(dim=0)
|
29 |
-
|
30 |
-
# Get predicted labels with probability greater than 0.5
|
31 |
-
predicted_labels = [label for i, label in enumerate(tokenizer.labels) if probabilities[i] > 0.5]
|
32 |
-
|
33 |
-
st.write("Predicted labels:", predicted_labels)
|
|
|
1 |
+
# Use a pipeline as a high-level helper
|
2 |
+
from transformers import pipeline
|
|
|
3 |
|
4 |
+
pipe = pipeline("text-classification", model="mavinsao/mi-roberta-classification")
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Streamlit app
|
7 |
st.title('Mental Illness Prediction')
|
|
|
11 |
|
12 |
# Prediction button
|
13 |
if st.button('Predict'):
|
14 |
+
|
15 |
+
st.write("Predicted labels:", pipe(sentence))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|