Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,10 +44,11 @@ def youtube_search(query, max_results=50):
|
|
| 44 |
logging.debug(f"Missing video ID or thumbnail for entry: {entry}")
|
| 45 |
else:
|
| 46 |
logging.warning("No entries found in search result.")
|
| 47 |
-
return gallery_items
|
| 48 |
except Exception as e:
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
# Function to display the video using the video URL
|
| 53 |
def show_video(video_url):
|
|
@@ -93,6 +94,7 @@ with gr.Blocks() as demo:
|
|
| 93 |
search_query_input = gr.Textbox(label="Search YouTube", placeholder="Enter your search query here")
|
| 94 |
search_button = gr.Button("Search")
|
| 95 |
search_output = gr.Gallery(label="Search Results", columns=5, height="1500px")
|
|
|
|
| 96 |
|
| 97 |
with gr.Column(scale=2):
|
| 98 |
selected_video_link = gr.Textbox(label="Selected Video Link", interactive=False)
|
|
@@ -101,9 +103,10 @@ with gr.Blocks() as demo:
|
|
| 101 |
|
| 102 |
# Define search button behavior
|
| 103 |
def update_search_results(query):
|
| 104 |
-
gallery_items = youtube_search(query)
|
| 105 |
-
|
| 106 |
-
|
|
|
|
| 107 |
|
| 108 |
# Update the selected video link field when a video is clicked in the gallery
|
| 109 |
def on_video_select(evt: gr.SelectData):
|
|
@@ -118,9 +121,9 @@ with gr.Blocks() as demo:
|
|
| 118 |
logging.debug(f"Playing video with URL: {video_url}")
|
| 119 |
return show_video(video_url)
|
| 120 |
|
| 121 |
-
search_button.click(update_search_results, inputs=search_query_input, outputs=search_output)
|
| 122 |
search_output.select(on_video_select, inputs=None, outputs=selected_video_link)
|
| 123 |
play_video_button.click(play_video, inputs=selected_video_link, outputs=video_output)
|
| 124 |
|
| 125 |
# Launch the Gradio interface
|
| 126 |
-
demo.launch()
|
|
|
|
| 44 |
logging.debug(f"Missing video ID or thumbnail for entry: {entry}")
|
| 45 |
else:
|
| 46 |
logging.warning("No entries found in search result.")
|
| 47 |
+
return gallery_items, ""
|
| 48 |
except Exception as e:
|
| 49 |
+
error_message = f"Error during YouTube yt-dlp request: {e}"
|
| 50 |
+
logging.error(error_message)
|
| 51 |
+
return [], error_message
|
| 52 |
|
| 53 |
# Function to display the video using the video URL
|
| 54 |
def show_video(video_url):
|
|
|
|
| 94 |
search_query_input = gr.Textbox(label="Search YouTube", placeholder="Enter your search query here")
|
| 95 |
search_button = gr.Button("Search")
|
| 96 |
search_output = gr.Gallery(label="Search Results", columns=5, height="1500px")
|
| 97 |
+
error_output = gr.Textbox(label="Error Message", interactive=False, visible=False)
|
| 98 |
|
| 99 |
with gr.Column(scale=2):
|
| 100 |
selected_video_link = gr.Textbox(label="Selected Video Link", interactive=False)
|
|
|
|
| 103 |
|
| 104 |
# Define search button behavior
|
| 105 |
def update_search_results(query):
|
| 106 |
+
gallery_items, error_message = youtube_search(query)
|
| 107 |
+
if error_message:
|
| 108 |
+
return [], error_message, gr.update(visible=True)
|
| 109 |
+
return gallery_items, "", gr.update(visible=False)
|
| 110 |
|
| 111 |
# Update the selected video link field when a video is clicked in the gallery
|
| 112 |
def on_video_select(evt: gr.SelectData):
|
|
|
|
| 121 |
logging.debug(f"Playing video with URL: {video_url}")
|
| 122 |
return show_video(video_url)
|
| 123 |
|
| 124 |
+
search_button.click(update_search_results, inputs=search_query_input, outputs=[search_output, error_output, error_output])
|
| 125 |
search_output.select(on_video_select, inputs=None, outputs=selected_video_link)
|
| 126 |
play_video_button.click(play_video, inputs=selected_video_link, outputs=video_output)
|
| 127 |
|
| 128 |
# Launch the Gradio interface
|
| 129 |
+
demo.launch()
|