mavinsao commited on
Commit
291793f
·
verified ·
1 Parent(s): a7d2103
Files changed (1) hide show
  1. app.py +5 -23
app.py CHANGED
@@ -1,13 +1,7 @@
1
- import torch
2
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
- import streamlit as st
4
 
5
- # Set device (GPU if available, otherwise CPU)
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
- # Tokenize the input sentence
21
- inputs = tokenizer(sentence, return_tensors="pt", padding=True, truncation=True).to(device)
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))