multimodalart HF staff commited on
Commit
7329846
·
verified ·
1 Parent(s): e16ccd6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ def search_huggingface_datasets(query):
5
+ if not query: # If the query is empty, return an empty list
6
+ return []
7
+ url = f"https://huggingface.co/api/quicksearch?q={query}&type=dataset&limit=20"
8
+ print(url)
9
+ response = requests.get(url)
10
+ if response.status_code == 200:
11
+ data = response.json()
12
+ print(data)
13
+ dataset_names = [d['id'] for d in data['datasets']]
14
+ return dataset_names
15
+ else:
16
+ return ["Error fetching datasets"]
17
+
18
+ def update_dropdown(query):
19
+ datasets = search_huggingface_datasets(query)
20
+ return gr.update(choices=datasets, visible=True)
21
+
22
+ with gr.Blocks() as demo:
23
+ with gr.Row():
24
+ dataset_dropdown = gr.Dropdown(label="Datasets", choices=[""], elem_id="dataset_list", interactive=True, filterable=True, allow_custom_value=True)
25
+ dataset_dropdown.change(update_dropdown, inputs=dataset_dropdown, outputs=dataset_dropdown, queue=False, show_progress="hidden")
26
+ demo.launch()