Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ from gtts import gTTS
|
|
4 |
from io import BytesIO
|
5 |
import random
|
6 |
import requests
|
7 |
-
|
8 |
|
9 |
# Initialize the empathy bot using llama_cpp
|
10 |
llm = Llama.from_pretrained(
|
@@ -60,25 +60,24 @@ def generate_dynamic_response(user_input):
|
|
60 |
|
61 |
return empathetic_response, suggested_activity, video_results
|
62 |
|
63 |
-
# Function to search for YouTube videos
|
64 |
-
def search_youtube_videos(query):
|
65 |
-
# Perform the search using youtube-search-python
|
66 |
-
videos_search = VideosSearch(query, limit=3)
|
67 |
-
results = videos_search.result()
|
68 |
-
|
69 |
-
# Collect video details
|
70 |
-
video_links = []
|
71 |
-
for video in results['videos']:
|
72 |
-
title = video['title']
|
73 |
-
link = video['link']
|
74 |
-
video_links.append((title, link))
|
75 |
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
78 |
|
|
|
|
|
|
|
|
|
|
|
79 |
return video_links
|
80 |
|
81 |
|
|
|
82 |
# Streamlit UI
|
83 |
st.title("Grief and Loss Support Bot πΏ")
|
84 |
st.markdown("Your compassionate companion in tough times π")
|
|
|
4 |
from io import BytesIO
|
5 |
import random
|
6 |
import requests
|
7 |
+
import yt_dlp
|
8 |
|
9 |
# Initialize the empathy bot using llama_cpp
|
10 |
llm = Llama.from_pretrained(
|
|
|
60 |
|
61 |
return empathetic_response, suggested_activity, video_results
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
def search_youtube_videos(query):
|
65 |
+
ydl_opts = {
|
66 |
+
'quiet': True,
|
67 |
+
'extract_flat': True,
|
68 |
+
'noplaylist': True,
|
69 |
+
'max_results': 3,
|
70 |
+
}
|
71 |
|
72 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
73 |
+
result = ydl.extract_info(f"ytsearch:{query}", download=False)
|
74 |
+
videos = result.get("entries", [])
|
75 |
+
video_links = [(video['title'], video['url']) for video in videos]
|
76 |
+
|
77 |
return video_links
|
78 |
|
79 |
|
80 |
+
|
81 |
# Streamlit UI
|
82 |
st.title("Grief and Loss Support Bot πΏ")
|
83 |
st.markdown("Your compassionate companion in tough times π")
|