Bey007 commited on
Commit
7309e11
Β·
verified Β·
1 Parent(s): 2df2245

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -4,7 +4,7 @@ from gtts import gTTS
4
  from io import BytesIO
5
  import random
6
  import requests
7
- from youtubesearchpython import VideosSearch
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
- if not video_links:
77
- video_links = [("No relevant videos found", "")] # Gracefully handle empty result
 
 
 
 
 
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 πŸ’š")