Bey007 commited on
Commit
503bff0
·
verified ·
1 Parent(s): 1be3ff5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -1,13 +1,15 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
  from gtts import gTTS
4
  from pytube import Search
5
  import random
6
  import os
7
 
8
- # Initialize pretrained Hugging Face models
9
- empathetic_response = pipeline("text2text-generation", model="mrm8488/t5-base-finetuned-empathy")
10
- sentiment_analysis = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
 
 
11
 
12
  # Configure Streamlit page
13
  st.set_page_config(page_title="Grief & Loss Support Bot", page_icon="🌱", layout="centered")
@@ -28,29 +30,31 @@ st.subheader("Your compassionate companion in tough times 💚")
28
  # User input
29
  user_input = st.text_input("How are you feeling today?", placeholder="Share your thoughts here...", max_chars=500)
30
 
31
- # Detect user sentiment and respond
32
  if user_input:
33
- sentiment = sentiment_analysis(user_input)[0]
34
- empathy_response = empathetic_response(user_input, max_length=100)[0]['generated_text']
 
 
 
35
 
36
  # Display empathetic response
37
- st.text_area("Bot's Response:", empathy_response, height=150)
38
-
39
  # Convert text to speech for added comfort
40
- tts = gTTS(empathy_response, lang='en')
41
  audio_file = "response.mp3"
42
  tts.save(audio_file)
43
  st.audio(audio_file, format="audio/mp3")
44
 
45
- # Activity Suggestion based on emotions detected
46
- mood = sentiment['label'].lower()
47
  activity_suggestions = {
48
  "positive": ["try journaling your feelings", "practice yoga", "learn a new recipe"],
49
  "neutral": ["take a short walk", "listen to calming music", "try some mindful breathing"],
50
  "negative": ["explore creative activities like painting", "watch a motivational video", "write down small goals to feel organized"]
51
  }
52
- activities = activity_suggestions.get(mood, ["try relaxation exercises", "reach out to someone you trust"])
53
-
54
  # Show dynamic activity suggestion
55
  st.info("Here’s something you could try to lift your spirits:")
56
  selected_activity = random.choice(activities)
@@ -61,7 +65,7 @@ if user_input:
61
  st.write("Recommended Videos:")
62
  for video in search.results[:2]: # Display top 2 videos
63
  st.write(f"[{video.title}]({video.watch_url})")
64
-
65
  # Crisis response if critical keywords are detected
66
  crisis_keywords = ["help", "suicide", "depressed", "emergency", "hurt", "lost"]
67
  if any(keyword in user_input.lower() for keyword in crisis_keywords):
 
1
  import streamlit as st
2
+ from llama_cpp import Llama
3
  from gtts import gTTS
4
  from pytube import Search
5
  import random
6
  import os
7
 
8
+ # Initialize the Llama model
9
+ llm = Llama.from_pretrained(
10
+ repo_id="featherless-ai-quants/HyunCello-KULLM3-empathy-v1.0-GGUF",
11
+ filename="HyunCello-KULLM3-empathy-v1.0-IQ4_XS.gguf"
12
+ )
13
 
14
  # Configure Streamlit page
15
  st.set_page_config(page_title="Grief & Loss Support Bot", page_icon="🌱", layout="centered")
 
30
  # User input
31
  user_input = st.text_input("How are you feeling today?", placeholder="Share your thoughts here...", max_chars=500)
32
 
33
+ # Generate empathetic response using Llama model
34
  if user_input:
35
+ response = llm.create_chat_completion(
36
+ messages=[
37
+ {"role": "user", "content": user_input}
38
+ ]
39
+ )['choices'][0]['message']['content']
40
 
41
  # Display empathetic response
42
+ st.text_area("Bot's Response:", response, height=150)
43
+
44
  # Convert text to speech for added comfort
45
+ tts = gTTS(response, lang='en')
46
  audio_file = "response.mp3"
47
  tts.save(audio_file)
48
  st.audio(audio_file, format="audio/mp3")
49
 
50
+ # Suggested activities based on user input
 
51
  activity_suggestions = {
52
  "positive": ["try journaling your feelings", "practice yoga", "learn a new recipe"],
53
  "neutral": ["take a short walk", "listen to calming music", "try some mindful breathing"],
54
  "negative": ["explore creative activities like painting", "watch a motivational video", "write down small goals to feel organized"]
55
  }
56
+ activities = activity_suggestions["neutral"] # Default to "neutral" for simplicity
57
+
58
  # Show dynamic activity suggestion
59
  st.info("Here’s something you could try to lift your spirits:")
60
  selected_activity = random.choice(activities)
 
65
  st.write("Recommended Videos:")
66
  for video in search.results[:2]: # Display top 2 videos
67
  st.write(f"[{video.title}]({video.watch_url})")
68
+
69
  # Crisis response if critical keywords are detected
70
  crisis_keywords = ["help", "suicide", "depressed", "emergency", "hurt", "lost"]
71
  if any(keyword in user_input.lower() for keyword in crisis_keywords):