Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ subprocess.check_call([sys.executable, "-m", "pip", "install", "httpx==0.18.2",
|
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
import requests
|
| 9 |
-
from bs4 import BeautifulSoup
|
| 10 |
import re
|
| 11 |
import yt_dlp
|
| 12 |
import logging
|
|
@@ -36,12 +35,14 @@ def youtube_search(query, max_results=50):
|
|
| 36 |
logging.debug(f"Number of entries found: {len(result['entries'])}")
|
| 37 |
for entry in result['entries']:
|
| 38 |
video_id = entry.get('id')
|
| 39 |
-
thumbnail_url = entry.get('thumbnail')
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
else:
|
| 44 |
-
logging.debug(f"Missing video ID
|
| 45 |
else:
|
| 46 |
logging.warning("No entries found in search result.")
|
| 47 |
return gallery_items, ""
|
|
@@ -106,7 +107,9 @@ with gr.Blocks() as demo:
|
|
| 106 |
gallery_items, error_message = youtube_search(query)
|
| 107 |
if error_message:
|
| 108 |
return [], error_message, gr.update(visible=True)
|
| 109 |
-
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# Update the selected video link field when a video is clicked in the gallery
|
| 112 |
def on_video_select(evt: gr.SelectData):
|
|
|
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
import requests
|
|
|
|
| 9 |
import re
|
| 10 |
import yt_dlp
|
| 11 |
import logging
|
|
|
|
| 35 |
logging.debug(f"Number of entries found: {len(result['entries'])}")
|
| 36 |
for entry in result['entries']:
|
| 37 |
video_id = entry.get('id')
|
| 38 |
+
thumbnail_url = entry.get('thumbnail') if entry.get('thumbnail') else "https://via.placeholder.com/150"
|
| 39 |
+
video_title = entry.get('title', "Unknown Title")
|
| 40 |
+
|
| 41 |
+
if video_id:
|
| 42 |
+
gallery_items.append((thumbnail_url, video_id, video_title))
|
| 43 |
+
logging.debug(f"Added video: ID={video_id}, Thumbnail={thumbnail_url}, Title={video_title}")
|
| 44 |
else:
|
| 45 |
+
logging.debug(f"Missing video ID for entry: {entry}")
|
| 46 |
else:
|
| 47 |
logging.warning("No entries found in search result.")
|
| 48 |
return gallery_items, ""
|
|
|
|
| 107 |
gallery_items, error_message = youtube_search(query)
|
| 108 |
if error_message:
|
| 109 |
return [], error_message, gr.update(visible=True)
|
| 110 |
+
# Display videos even if the title or thumbnail is missing by using placeholders
|
| 111 |
+
gallery_items_display = [(item[0], item[1]) for item in gallery_items] # Show thumbnail and video ID only
|
| 112 |
+
return gallery_items_display, "", gr.update(visible=False)
|
| 113 |
|
| 114 |
# Update the selected video link field when a video is clicked in the gallery
|
| 115 |
def on_video_select(evt: gr.SelectData):
|