Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,24 +40,27 @@ if user_input:
|
|
40 |
sentiment = sentiment_analysis(user_input)[0]
|
41 |
|
42 |
# Generate empathetic response with increased length and more context
|
43 |
-
response = conversational_bot(user_input, max_length=300, num_return_sequences=
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
52 |
|
53 |
# Store the response for future comparison
|
54 |
-
st.session_state.previous_response =
|
55 |
|
56 |
# Display response
|
57 |
-
st.text_area("Bot's Response:",
|
58 |
|
59 |
# Text-to-speech output
|
60 |
-
tts = gTTS(
|
61 |
audio_file = "response.mp3"
|
62 |
tts.save(audio_file)
|
63 |
st.audio(audio_file, format="audio/mp3")
|
|
|
40 |
sentiment = sentiment_analysis(user_input)[0]
|
41 |
|
42 |
# Generate empathetic response with increased length and more context
|
43 |
+
response = conversational_bot(user_input, max_length=300, num_return_sequences=3, temperature=0.9, top_k=50)
|
44 |
|
45 |
+
# Choose the response that does not repeat what the user said
|
46 |
+
best_response = ""
|
47 |
+
for generated in response:
|
48 |
+
if user_input.lower() not in generated['generated_text'].lower():
|
49 |
+
best_response = generated['generated_text']
|
50 |
+
break
|
51 |
+
|
52 |
+
# If no diverse response was found, generate a default supportive message
|
53 |
+
if not best_response:
|
54 |
+
best_response = "I understand how you're feeling. You're not alone in this. I'm here to listen and help."
|
55 |
|
56 |
# Store the response for future comparison
|
57 |
+
st.session_state.previous_response = best_response
|
58 |
|
59 |
# Display response
|
60 |
+
st.text_area("Bot's Response:", best_response, height=250)
|
61 |
|
62 |
# Text-to-speech output
|
63 |
+
tts = gTTS(best_response, lang='en')
|
64 |
audio_file = "response.mp3"
|
65 |
tts.save(audio_file)
|
66 |
st.audio(audio_file, format="audio/mp3")
|