Bey007 commited on
Commit
3812715
1 Parent(s): 00c5cdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -39,13 +39,13 @@ if 'previous_responses' not in st.session_state:
39
  # Check if user has entered text
40
  if user_input:
41
  # Refined prompt for better empathetic responses
42
- prompt = f"The user is expressing their feelings of grief, loss, or overwhelm. Respond with empathy and support. User's input: {user_input}"
43
 
44
  # Run the text generation model to generate a response based on user input
45
- generated_responses = generator(prompt, max_length=250, num_return_sequences=3, temperature=0.7)
46
 
47
  # Filter out any responses that are too similar to previous responses or user input
48
- new_responses = [response['generated_text'] for response in generated_responses]
49
  new_responses = [resp for resp in new_responses if resp.lower() not in [prev.lower() for prev in st.session_state.previous_responses] and resp.lower() != user_input.lower()]
50
 
51
  # If there are valid new responses, pick one, otherwise fallback
@@ -100,8 +100,11 @@ if user_input:
100
  # Search YouTube for videos related to the selected activity
101
  search = Search(activity)
102
  search_results = search.results[:3] # limit results to 3 videos
103
- for video in search_results:
104
- st.write(f"[{video.title}]({video.watch_url})")
 
 
 
105
 
106
  # Crisis resources
107
  crisis_keywords = ["help", "suicide", "depressed", "emergency", "hurt", "lost"]
 
39
  # Check if user has entered text
40
  if user_input:
41
  # Refined prompt for better empathetic responses
42
+ prompt = f"User is feeling overwhelmed with emotional distress and is going through a tough time. Respond empathetically, offering support and understanding. The user's input: {user_input}"
43
 
44
  # Run the text generation model to generate a response based on user input
45
+ generated_responses = generator(prompt, max_length=200, num_return_sequences=3, temperature=0.7)
46
 
47
  # Filter out any responses that are too similar to previous responses or user input
48
+ new_responses = [response['generated_text'].strip() for response in generated_responses]
49
  new_responses = [resp for resp in new_responses if resp.lower() not in [prev.lower() for prev in st.session_state.previous_responses] and resp.lower() != user_input.lower()]
50
 
51
  # If there are valid new responses, pick one, otherwise fallback
 
100
  # Search YouTube for videos related to the selected activity
101
  search = Search(activity)
102
  search_results = search.results[:3] # limit results to 3 videos
103
+ if search_results:
104
+ for video in search_results:
105
+ st.write(f"[{video.title}]({video.watch_url})")
106
+ else:
107
+ st.write("Sorry, I couldn't find any relevant videos at the moment.")
108
 
109
  # Crisis resources
110
  crisis_keywords = ["help", "suicide", "depressed", "emergency", "hurt", "lost"]