Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines91011121213141523 unmodified lines394041424243444522 unmodified lines686970717273747576777172737475767778798081818283848485868586878889906 unmodified lines979899991001011021038 unmodified lines
# Step 1with open("Mental health chatbot text.txt", "r", encoding="utf-8") as f: skincare_text = f.read() mental_health_text = f.read()
# Step 2: Preprocess text into sentence chunksdef preprocess_text(text):23 unmodified lines print(f"Sample chunks: {final_chunks[:3]}") return final_chunks
cleaned_chunks = preprocess_text(skincare_text)cleaned_chunks = preprocess_text(mental_health_text)
# Step 3: Convert chunks into embeddingsmodel = SentenceTransformer('all-MiniLM-L6-v2')22 unmodified lines return results, top_scores[:len(results)]
# Step 5: Relevance checkerdef is_skincare_related(query): skincare_keywords = [ 'skin', 'skincare', 'acne', 'wrinkles', 'moisturizer', 'cleanser', 'sunscreen', 'serum', 'retinol', 'vitamin', 'dry', 'oily', 'sensitive', 'aging', 'pores', 'blackheads', 'routine', 'face', 'facial', 'beauty', 'dermatology', 'cosmetic', 'cream', 'lotion', 'toner', 'exfoliate', 'hydration', 'anti-aging', 'blemish', 'spot', 'dark circles'def is_mental_health_related(query): mental_health_keywords = [ 'anxiety', 'depression', 'stress', 'mental health', 'therapy', 'counseling', 'mood', 'emotions', 'feelings', 'wellbeing', 'self-care', 'mindfulness', 'meditation', 'coping', 'support', 'psychology', 'psychiatry', 'bipolar', 'trauma', 'PTSD', 'panic', 'worry', 'sad', 'happy', 'angry', 'fear', 'self-esteem', 'confidence', 'resilience', 'healing', 'recovery', 'mental', 'emotional', 'psychological', 'behavioral', 'cognitive' ] query_lower = query.lower() return any(keyword in query_lower for keyword in skincare_keywords) return any(keyword in query_lower for keyword in mental_health_keywords)
queries = [ "Consistent skincare routine", "Applying sunscreen daily", "Choosing products that match your skin type" "Managing daily stress and anxiety", "Building healthy coping mechanisms", "Practicing mindfulness and self-care"]
for q in queries:6 unmodified lines top_results = get_top_chunks(message, chunk_embeddings, cleaned_chunks) print(top_results) messages = [{"role": "system", "content": f"You are a friendly chatbot. You give people advice about skincare. Base your response on the following information: {top_results}"}] messages = [{"role": "system", "content": f"You are a friendly chatbot. You give people advice about mental-health. Base your response on the following information: {top_results}"}] if history: messages.extend(history)app.py+15-14