DrSyedFaizan commited on
Commit
d699c8e
·
verified ·
1 Parent(s): b61a1eb

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +48 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
+
5
+ # Define model and tokenizer paths from Hugging Face
6
+ MODEL_PATH = "DrSyedFaizan/mindBERT"
7
+
8
+ # Load tokenizer and model from Hugging Face Hub
9
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
10
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH, from_safetensors=True)
11
+
12
+ # Streamlit UI setup
13
+ st.title("MindBERT - Mental Health Analysis Chat")
14
+ st.write("Enter a message, and the model will analyze the mental state of the writer.")
15
+
16
+ user_input = st.text_area("Type your message here:")
17
+
18
+ if st.button("Analyze Mental State"):
19
+ if user_input.strip():
20
+ # Tokenize input
21
+ inputs = tokenizer(user_input, return_tensors="pt", truncation=True, padding=True)
22
+
23
+ # Make prediction
24
+ with torch.no_grad():
25
+ outputs = model(**inputs)
26
+ logits = outputs.logits
27
+ predicted_class = torch.argmax(logits, dim=1).item()
28
+
29
+ # Mapping predicted class to mental state
30
+ label_map = {
31
+ 0: "Anxiety",
32
+ 1: "Bipolar",
33
+ 2: "Depression",
34
+ 3: "Normal",
35
+ 4: "Personality Disorder",
36
+ 5: "Stress",
37
+ 6: "Suicidal"
38
+ }
39
+ mental_state = label_map.get(predicted_class, "Unknown")
40
+
41
+ # Display results
42
+ st.write(f"Predicted Mental State: **{mental_state}**")
43
+ else:
44
+ st.warning("Please enter some text for analysis.")
45
+
46
+ # Footer
47
+ st.markdown("---")
48
+ st.markdown("Developed by Dr. Syed Faizan using MindBERT on Hugging Face.")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ streamlit
3
+ torch
4
+ safetensors
5
+