Spaces:
Runtime error
Runtime error
File size: 3,597 Bytes
10e4cb6 3a64fb1 10e4cb6 34a4f65 a4cce9a 34a4f65 9903fee 72d0e7a 34a4f65 72d0e7a 9903fee 34a4f65 9903fee be8b77d 9903fee 61d9513 72d0e7a 9903fee 3a64fb1 61d9513 3a64fb1 10e4cb6 3a64fb1 10e4cb6 3a64fb1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
import streamlit as st
from transformers import AutoTokenizer
from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM
from datasets import load_dataset
# Replace with the direct image URL
flower_image_url = "https://i.postimg.cc/hG2FG85D/2.png"
# Inject custom CSS for the background with a centered and blurred image
st.markdown(
f"""
<style>
/* Container for background */
html, body {{
margin: 0;
padding: 0;
overflow: hidden;
}}
[data-testid="stAppViewContainer"] {{
position: relative;
z-index: 1; /* Ensure UI elements are above the background */
}}
/* Blurred background image */
.blurred-background {{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1; /* Send background image behind all UI elements */
background-image: url("{flower_image_url}");
background-size: cover;
background-position: center;
filter: blur(10px); /* Adjust blur ratio here */
opacity: 0.8; /* Optional: Add slight transparency for a subtle effect */
}}
</style>
""",
unsafe_allow_html=True
)
# Add the blurred background div
st.markdown('<div class="blurred-background"></div>', unsafe_allow_html=True)
# Load the fine-tuned model and tokenizer
@st.cache_resource
def load_model_and_tokenizer():
config = PeftConfig.from_pretrained("zementalist/llama-3-8B-chat-psychotherapist")
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct")
model = PeftModel.from_pretrained(base_model, "zementalist/llama-3-8B-chat-psychotherapist")
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct")
return model, tokenizer
model, tokenizer = load_model_and_tokenizer()
# Load dataset for reference (optional)
@st.cache_resource
def load_dataset_reference():
return load_dataset("Amod/mental_health_counseling_conversations")
dataset = load_dataset_reference()
# Streamlit App Configuration
st.title("Mental Well-Being Support Application")
st.markdown("""
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.
""")
# User Input Section
st.header("Your Mental Health Journey")
user_query = st.text_area("Please share your thoughts or questions:", placeholder="Write here...")
# Generate AI Response
if st.button("Get Supportive Response"):
if user_query.strip():
# Generate response
inputs = tokenizer(f"User: {user_query}\nAI:", return_tensors="pt")
outputs = model.generate(inputs.input_ids, max_length=200, temperature=0.7, num_return_sequences=1)
ai_response = tokenizer.decode(outputs[0], skip_special_tokens=True).split("AI:")[-1].strip()
# Display the response
st.subheader("Your Supportive Response:")
st.write(ai_response)
else:
st.error("Please enter a question or concern to get a response.")
# Additional Resources Section
st.sidebar.header("Resources")
st.sidebar.markdown("""
- [Mental Health Foundation](https://www.mentalhealth.org)
- [Mind](https://www.mind.org.uk)
- [National Suicide Prevention Lifeline](https://suicidepreventionlifeline.org)
""")
# Footer
st.sidebar.info("This application is not a replacement for professional help. If you're in crisis, please contact a mental health professional.")
|