Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines910111213141523 unmodified lines3940414243444522 unmodified lines686970717273747576777879808182838485868788896 unmodified lines969798991001011028 unmodified lines# Step 1with open("Mental health chatbot text.txt", "r", encoding="utf-8") as f:skincare_text = f.read()# Step 2: Preprocess text into sentence chunksdef preprocess_text(text):23 unmodified linesprint(f"Sample chunks: {final_chunks[:3]}")return final_chunkscleaned_chunks = preprocess_text(skincare_text)# Step 3: Convert chunks into embeddingsmodel = SentenceTransformer('all-MiniLM-L6-v2')22 unmodified linesreturn 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']query_lower = query.lower()return any(keyword in query_lower for keyword in skincare_keywords)queries = ["Consistent skincare routine","Applying sunscreen daily","Choosing products that match your skin type"]for q in queries:6 unmodified linestop_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}"}]if history:messages.extend(history)8 unmodified lines910111213141523 unmodified lines3940414243444522 unmodified lines68697071727374757677787980818283848586878889906 unmodified lines9798991001011021038 unmodified lines# Step 1with open("Mental health chatbot text.txt", "r", encoding="utf-8") as f:mental_health_text = f.read()# Step 2: Preprocess text into sentence chunksdef preprocess_text(text):23 unmodified linesprint(f"Sample chunks: {final_chunks[:3]}")return final_chunkscleaned_chunks = preprocess_text(mental_health_text)# Step 3: Convert chunks into embeddingsmodel = SentenceTransformer('all-MiniLM-L6-v2')22 unmodified linesreturn results, top_scores[:len(results)]# Step 5: Relevance checkerdef 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 mental_health_keywords)queries = ["Managing daily stress and anxiety","Building healthy coping mechanisms","Practicing mindfulness and self-care"]for q in queries:6 unmodified linestop_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 mental-health. Base your response on the following information: {top_results}"}]if history:messages.extend(history)
app.py+15-14