Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,17 +30,28 @@ st.subheader("Your compassionate companion in tough times 💚")
|
|
30 |
# Get user input
|
31 |
user_input = st.text_input("Share what's on your mind...", placeholder="Type here...", max_chars=500)
|
32 |
|
|
|
|
|
|
|
|
|
33 |
# Check if user has entered text
|
34 |
if user_input:
|
35 |
# Run sentiment analysis to check for distress
|
36 |
sentiment = sentiment_analysis(user_input)[0]
|
37 |
|
38 |
# Generate empathetic response (model generates responses with empathy)
|
39 |
-
response = conversational_bot(user_input, max_length=150)[0]['generated_text']
|
40 |
|
41 |
# Ensure response does not repeat what the user said, and is supportive
|
42 |
if user_input.lower() in response.lower():
|
43 |
response = "I understand how you're feeling. You're not alone in this. I'm here to listen and help."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# Display response
|
46 |
st.text_area("Bot's Response:", response, height=150)
|
@@ -59,7 +70,7 @@ if user_input:
|
|
59 |
|
60 |
# Search YouTube for videos related to the selected activity
|
61 |
search = Search(activity)
|
62 |
-
search_results = search.results[:
|
63 |
for video in search_results:
|
64 |
st.write(f"[{video.title}]({video.watch_url})")
|
65 |
|
|
|
30 |
# Get user input
|
31 |
user_input = st.text_input("Share what's on your mind...", placeholder="Type here...", max_chars=500)
|
32 |
|
33 |
+
# Store previous response to check for repetition
|
34 |
+
if 'previous_response' not in st.session_state:
|
35 |
+
st.session_state.previous_response = ""
|
36 |
+
|
37 |
# Check if user has entered text
|
38 |
if user_input:
|
39 |
# Run sentiment analysis to check for distress
|
40 |
sentiment = sentiment_analysis(user_input)[0]
|
41 |
|
42 |
# Generate empathetic response (model generates responses with empathy)
|
43 |
+
response = conversational_bot(user_input, max_length=150, num_return_sequences=1, temperature=0.9, top_k=50)[0]['generated_text']
|
44 |
|
45 |
# Ensure response does not repeat what the user said, and is supportive
|
46 |
if user_input.lower() in response.lower():
|
47 |
response = "I understand how you're feeling. You're not alone in this. I'm here to listen and help."
|
48 |
+
|
49 |
+
# Check if the response is too similar to the previous one, if so, generate a new one
|
50 |
+
if response == st.session_state.previous_response:
|
51 |
+
response = conversational_bot(user_input, max_length=150, num_return_sequences=1, temperature=0.9, top_k=50)[0]['generated_text']
|
52 |
+
|
53 |
+
# Store the response for future comparison
|
54 |
+
st.session_state.previous_response = response
|
55 |
|
56 |
# Display response
|
57 |
st.text_area("Bot's Response:", response, height=150)
|
|
|
70 |
|
71 |
# Search YouTube for videos related to the selected activity
|
72 |
search = Search(activity)
|
73 |
+
search_results = search.results[:3] # limit results to 3 videos
|
74 |
for video in search_results:
|
75 |
st.write(f"[{video.title}]({video.watch_url})")
|
76 |
|