Bey007 commited on
Commit
d5483a5
·
verified ·
1 Parent(s): 8430ee5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -36,8 +36,8 @@ def generate_story(theme):
36
  return story
37
 
38
  def generate_response(user_input):
39
- # Empathy-focused prompt to guide the bot
40
- response_prompt = f"The user has shared the following: '{user_input}'. Respond with empathy, compassion, and understanding. Acknowledge their sadness and offer comforting, reassuring words. Show that you care and validate their feelings without giving unsolicited advice."
41
 
42
  # Generate the response using the GPT-2 model
43
  input_ids = gpt2_tokenizer.encode(response_prompt, return_tensors='pt')
@@ -54,12 +54,11 @@ def generate_response(user_input):
54
  response = gpt2_tokenizer.decode(response_ids[0], skip_special_tokens=True)
55
 
56
  # Strip out the prompt portion to get a clean, empathetic message
57
- cleaned_response = response.replace(f"The user has shared the following: '{user_input}'. Respond with empathy, compassion, and understanding. Acknowledge their sadness and offer comforting, reassuring words. Show that you care and validate their feelings without giving unsolicited advice.", "").strip()
58
 
59
  return cleaned_response
60
 
61
 
62
-
63
  # Analyze user input for emotional tone
64
  def get_emotion(user_input):
65
  emotions = emotion_classifier(user_input)
 
36
  return story
37
 
38
  def generate_response(user_input):
39
+ # Refined prompt focusing only on empathetic and supportive language
40
+ response_prompt = f"You are a compassionate and empathetic support bot. A user has shared their feelings: '{user_input}'. Please respond with empathy, validation of their emotions, and offer support without providing unsolicited advice. Be reassuring and comforting, showing understanding of their emotional pain."
41
 
42
  # Generate the response using the GPT-2 model
43
  input_ids = gpt2_tokenizer.encode(response_prompt, return_tensors='pt')
 
54
  response = gpt2_tokenizer.decode(response_ids[0], skip_special_tokens=True)
55
 
56
  # Strip out the prompt portion to get a clean, empathetic message
57
+ cleaned_response = response.replace(f"You are a compassionate and empathetic support bot. A user has shared their feelings: '{user_input}'. Please respond with empathy, validation of their emotions, and offer support without providing unsolicited advice. Be reassuring and comforting, showing understanding of their emotional pain.", "").strip()
58
 
59
  return cleaned_response
60
 
61
 
 
62
  # Analyze user input for emotional tone
63
  def get_emotion(user_input):
64
  emotions = emotion_classifier(user_input)