Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,8 +36,8 @@ def generate_story(theme):
|
|
36 |
return story
|
37 |
|
38 |
def generate_response(user_input):
|
39 |
-
# Refined prompt
|
40 |
-
response_prompt = f"You are a
|
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
|
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)
|