Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,50 +44,56 @@ st.markdown(
|
|
44 |
# Add the blurred background div
|
45 |
st.markdown('<div class="blurred-background"></div>', unsafe_allow_html=True)
|
46 |
|
|
|
47 |
@st.cache_resource
|
48 |
-
def
|
49 |
-
return
|
50 |
|
51 |
-
|
52 |
|
53 |
-
# Load
|
54 |
@st.cache_resource
|
55 |
-
def
|
56 |
-
return
|
57 |
|
58 |
-
|
59 |
|
60 |
-
# Streamlit
|
61 |
-
st.title("Mental
|
62 |
st.markdown("""
|
63 |
-
Welcome to the Mental
|
|
|
64 |
""")
|
65 |
|
66 |
-
#
|
67 |
-
st.
|
68 |
-
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
#
|
71 |
-
|
72 |
-
if user_query.strip():
|
73 |
-
# Generate response
|
74 |
-
inputs = tokenizer(f"User: {user_query}\nAI:", return_tensors="pt")
|
75 |
-
outputs = model.generate(inputs.input_ids, max_length=200, temperature=0.7, num_return_sequences=1)
|
76 |
-
ai_response = tokenizer.decode(outputs[0], skip_special_tokens=True).split("AI:")[-1].strip()
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
else:
|
82 |
-
st.error("Please enter a question or concern to
|
83 |
|
84 |
-
#
|
85 |
-
st.sidebar.header("Resources")
|
86 |
st.sidebar.markdown("""
|
87 |
- [Mental Health Foundation](https://www.mentalhealth.org)
|
88 |
- [Mind](https://www.mind.org.uk)
|
89 |
- [National Suicide Prevention Lifeline](https://suicidepreventionlifeline.org)
|
90 |
""")
|
91 |
|
92 |
-
|
93 |
-
st.sidebar.info("This application is not a replacement for professional help. If you're in crisis, please contact a mental health professional.")
|
|
|
44 |
# Add the blurred background div
|
45 |
st.markdown('<div class="blurred-background"></div>', unsafe_allow_html=True)
|
46 |
|
47 |
+
# Load dataset for context
|
48 |
@st.cache_resource
|
49 |
+
def load_counseling_dataset():
|
50 |
+
return load_dataset("Amod/mental_health_counseling_conversations")
|
51 |
|
52 |
+
dataset = load_counseling_dataset()
|
53 |
|
54 |
+
# Load a Hugging Face-compatible text-generation model
|
55 |
@st.cache_resource
|
56 |
+
def load_text_generation_model():
|
57 |
+
return pipeline("text-generation", model="meta-llama/Llama-2-7b-chat-hf")
|
58 |
|
59 |
+
text_generator = load_text_generation_model()
|
60 |
|
61 |
+
# Streamlit app
|
62 |
+
st.title("Mental Health Counseling Chat")
|
63 |
st.markdown("""
|
64 |
+
Welcome to the Mental Health Counseling Chat application.
|
65 |
+
This platform is designed to provide supportive, positive, and encouraging responses based on mental health counseling expertise.
|
66 |
""")
|
67 |
|
68 |
+
# Explore dataset for additional context or resources (optional)
|
69 |
+
if st.checkbox("Show Example Questions and Answers from Dataset"):
|
70 |
+
sample = dataset["train"].shuffle(seed=42).select(range(3)) # Display 3 random samples
|
71 |
+
for example in sample:
|
72 |
+
st.markdown(f"**Question:** {example['context']}")
|
73 |
+
st.markdown(f"**Answer:** {example['response']}")
|
74 |
+
st.markdown("---")
|
75 |
|
76 |
+
# User input for mental health concerns
|
77 |
+
user_input = st.text_area("Your question or concern:", placeholder="Type here...")
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
+
if st.button("Get Supportive Response"):
|
80 |
+
if user_input.strip():
|
81 |
+
# Generate response using the model
|
82 |
+
prompt = f"User: {user_input}\nCounselor:"
|
83 |
+
response = text_generator(prompt, max_length=200, num_return_sequences=1)
|
84 |
+
counselor_reply = response[0]["generated_text"].split("Counselor:")[-1].strip()
|
85 |
+
|
86 |
+
st.subheader("Counselor's Response:")
|
87 |
+
st.write(counselor_reply)
|
88 |
else:
|
89 |
+
st.error("Please enter a question or concern to receive a response.")
|
90 |
|
91 |
+
# Sidebar resources
|
92 |
+
st.sidebar.header("Additional Mental Health Resources")
|
93 |
st.sidebar.markdown("""
|
94 |
- [Mental Health Foundation](https://www.mentalhealth.org)
|
95 |
- [Mind](https://www.mind.org.uk)
|
96 |
- [National Suicide Prevention Lifeline](https://suicidepreventionlifeline.org)
|
97 |
""")
|
98 |
|
99 |
+
st.sidebar.info("This application is not a replacement for professional counseling. If you are in crisis, please seek professional help immediately.")
|
|