Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,10 +37,10 @@ def generate_story(theme):
|
|
37 |
|
38 |
|
39 |
def generate_response(user_input):
|
40 |
-
#
|
41 |
-
response_prompt = f"User shares: '{user_input}'. Respond with empathy
|
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,15 +51,18 @@ def generate_response(user_input):
|
|
51 |
num_return_sequences=1
|
52 |
)
|
53 |
|
54 |
-
# Decode and
|
55 |
response = gpt2_tokenizer.decode(response_ids[0], skip_special_tokens=True)
|
56 |
|
57 |
-
# Clean
|
58 |
-
cleaned_response = response.replace(f"
|
|
|
|
|
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)
|