import gradio as gr import requests def search_huggingface_datasets(query): if not query: # If the query is empty, return an empty list return [] url = f"https://huggingface.co/api/quicksearch?q={query}&type=dataset&limit=20" print(url) response = requests.get(url) if response.status_code == 200: data = response.json() print(data) dataset_names = [d['id'] for d in data['datasets']] return dataset_names else: return ["Error fetching datasets"] def update_dropdown(query): datasets = search_huggingface_datasets(query) return gr.update(choices=datasets, visible=True) with gr.Blocks() as demo: with gr.Row(): dataset_dropdown = gr.Dropdown(label="Datasets", choices=[""], elem_id="dataset_list", interactive=True, filterable=True, allow_custom_value=True) dataset_dropdown.change(update_dropdown, inputs=dataset_dropdown, outputs=dataset_dropdown, queue=False, show_progress="hidden") demo.launch()