Bey007 commited on
Commit
872728d
·
verified ·
1 Parent(s): d5483a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -36,8 +36,8 @@ def generate_story(theme):
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,11 +54,12 @@ 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"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)
 
36
  return story
37
 
38
  def generate_response(user_input):
39
+ # Refined prompt with a clear and empathetic tone
40
+ response_prompt = f"You are a kind and empathetic support bot. A user is sharing their feelings: '{user_input}'. Respond with kindness and empathy, offering emotional validation. Keep the tone soft and comforting, and avoid any philosophical or unrelated explanations. Offer support and let them know that their feelings are valid."
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 kind and empathetic support bot. A user is sharing their feelings: '{user_input}'. Respond with kindness and empathy, offering emotional validation. Keep the tone soft and comforting, and avoid any philosophical or unrelated explanations. Offer support and let them know that their feelings are valid.", "").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)