Spaces:
Runtime error
Runtime error
| # import gradio as gr | |
| # from youtubesearchpython import VideosSearch | |
| # import sys | |
| # from io import StringIO | |
| # # PATCH: Remove the problematic proxies parameter | |
| # def search_youtube(query, max_results=15): | |
| # try: | |
| # print(f"π Searching for: {query}") | |
| # # Try with limit first | |
| # try: | |
| # results = VideosSearch(query, limit=max_results).result()['result'] | |
| # except TypeError as e: | |
| # if "proxies" in str(e): | |
| # # If proxies error, try without limit | |
| # print("β οΈ Version compatibility fix applied...") | |
| # search = VideosSearch(query) | |
| # results = search.result()['result'][:max_results] | |
| # else: | |
| # raise e | |
| # videos = [] | |
| # for video in results: | |
| # videos.append({ | |
| # 'title': video.get('title', 'No Title'), | |
| # 'url': video.get('url_suffix', ''), | |
| # 'channel': video.get('channel', 'Unknown'), | |
| # 'duration': video.get('duration', 'N/A'), | |
| # 'views': video.get('views', 'N/A') | |
| # }) | |
| # print(f"β Found {len(videos)} videos") | |
| # return videos | |
| # except Exception as e: | |
| # print(f"β Error: {e}") | |
| # return [] | |
| # # This works in: Colab, HF Spaces, Local, ANY Python environment | |
| # def search_and_display(query, max_results): | |
| # log_capture = StringIO() | |
| # sys.stdout = log_capture | |
| # try: | |
| # videos = search_youtube(query, int(max_results)) | |
| # if not videos: | |
| # display_text = "β No videos found" | |
| # else: | |
| # display_text = f"πΊ **Found {len(videos)} videos**\n\n" | |
| # for i, video in enumerate(videos, 1): | |
| # display_text += f"**{i}. {video['title']}**\n" | |
| # display_text += f" πΉ Channel: {video['channel']}\n" | |
| # display_text += f" β±οΈ Duration: {video['duration']}\n" | |
| # display_text += f" ποΈ Views: {video['views']}\n" | |
| # display_text += f" π https://youtube.com{video['url']}\n\n" | |
| # logs = log_capture.getvalue() | |
| # return display_text, logs if logs else "β Done!" | |
| # finally: | |
| # sys.stdout = sys.__stdout__ | |
| # # Create Gradio interface | |
| # with gr.Blocks() as demo: | |
| # gr.Markdown("# π YouTube Search") | |
| # with gr.Row(): | |
| # query = gr.Textbox(label="Search", placeholder="Enter search...", scale=3) | |
| # max_res = gr.Slider(label="Results", minimum=5, maximum=30, value=15, step=5, scale=1) | |
| # btn = gr.Button("Search") | |
| # with gr.Row(): | |
| # results = gr.Markdown(label="Results") | |
| # logs = gr.Textbox(label="Logs", lines=15, interactive=False) | |
| # btn.click(search_and_display, [query, max_res], [results, logs]) | |
| # demo.launch() | |
| import requests | |
| requests.get("https://api.ipify.org?format=json").json() | |