tahirsher commited on
Commit
d02fed4
·
verified ·
1 Parent(s): 7ffd344

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -28
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 load_pipeline():
49
- return pipeline("text-generation", model="QuantFactory/Mental-Health-FineTuned-Mistral-7B-Instruct-v0.2-GGUF")
50
 
51
- text_generation_pipe = load_pipeline()
52
 
53
- # Load dataset for reference (optional)
54
  @st.cache_resource
55
- def load_dataset_reference():
56
- return load_dataset("Amod/mental_health_counseling_conversations")
57
 
58
- dataset = load_dataset_reference()
59
 
60
- # Streamlit App Configuration
61
- st.title("Mental Well-Being Support Application")
62
  st.markdown("""
63
- Welcome to the Mental Well-Being Support Application. This platform is designed to provide positive, supportive, and encouraging responses to your mental health concerns. Our responses are powered by a fine-tuned AI model based on expert psychologists' answers.
 
64
  """)
65
 
66
- # User Input Section
67
- st.header("Your Mental Health Journey")
68
- user_query = st.text_area("Please share your thoughts or questions:", placeholder="Write here...")
 
 
 
 
69
 
70
- # Generate AI Response
71
- if st.button("Get Supportive Response"):
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
- # Display the response
79
- st.subheader("Your Supportive Response:")
80
- st.write(ai_response)
 
 
 
 
 
 
81
  else:
82
- st.error("Please enter a question or concern to get a response.")
83
 
84
- # Additional Resources Section
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
- # Footer
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.")