Bey007 commited on
Commit
4839250
·
verified ·
1 Parent(s): 32a5ab7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -37,10 +37,10 @@ def generate_story(theme):
37
 
38
 
39
  def generate_response(user_input):
40
- # Update the prompt to be more natural and empathetic.
41
- response_prompt = f"User shares: '{user_input}'. Respond with empathy, encouragement, and reassurance. Be kind and understanding, offering support for their situation."
42
 
43
- # Generate the response using the model (this could be GPT-2 or DialoGPT).
44
  input_ids = gpt2_tokenizer.encode(response_prompt, return_tensors='pt')
45
  response_ids = gpt2_model.generate(
46
  input_ids,
@@ -51,15 +51,18 @@ def generate_response(user_input):
51
  num_return_sequences=1
52
  )
53
 
54
- # Decode and return the response
55
  response = gpt2_tokenizer.decode(response_ids[0], skip_special_tokens=True)
56
 
57
- # Clean up the response to avoid the model repeating the prompt
58
- cleaned_response = response.replace(f"You are a compassionate, kind,and empathetic support bot. A user has shared their feelings: '{user_input}'. Respond with empathy, encouragement, and motivation.", "").strip()
 
 
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)
 
37
 
38
 
39
  def generate_response(user_input):
40
+ # Enhanced empathetic prompt
41
+ response_prompt = f"User shares: '{user_input}'. Respond with empathy and understanding. Acknowledge their feelings and offer words of comfort and encouragement. Your response should focus on offering reassurance and emotional support, not practical advice."
42
 
43
+ # Generate the response using the model
44
  input_ids = gpt2_tokenizer.encode(response_prompt, return_tensors='pt')
45
  response_ids = gpt2_model.generate(
46
  input_ids,
 
51
  num_return_sequences=1
52
  )
53
 
54
+ # Decode and clean up the response
55
  response = gpt2_tokenizer.decode(response_ids[0], skip_special_tokens=True)
56
 
57
+ # Clean response from repeating the prompt
58
+ cleaned_response = response.replace(f"User shares: '{user_input}'. Respond with empathy and understanding. Acknowledge their feelings and offer words of comfort and encouragement. Your response should focus on offering reassurance and emotional support, not practical advice.", "").strip()
59
+
60
+ # Return the cleaned response
61
  return cleaned_response
62
 
63
 
64
 
65
+
66
  # Analyze user input for emotional tone
67
  def get_emotion(user_input):
68
  emotions = emotion_classifier(user_input)