multimodalart's picture
Update app.py
833a47b verified
import gradio as gr
import requests
def quick_search_query(query, repo_type):
if not query:
return []
url = f"https://huggingface.co/api/quicksearch?q={query}&type={repo_type}&limit=20"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
repo_names = [d['id'] for d in data[f"{repo_type}s"]]
return repo_names
else:
return ["Error fetching repo"]
def update_dropdown(query, repo_type, key_up_data: gr.KeyUpData):
datasets = quick_search_query(key_up_data.input_value, repo_type)
return gr.update(choices=datasets, visible=True)
with gr.Blocks() as demo:
model_dropdown = gr.Dropdown(label="Models Auto-Complete", choices=[""], allow_custom_value=True)
model_dropdown.key_up(fn=update_dropdown, inputs=[model_dropdown, gr.State("model")], outputs=model_dropdown, queue=False, show_progress="hidden")
dataset_dropdown = gr.Dropdown(label="Datasets Auto-Complete", choices=[""], allow_custom_value=True)
dataset_dropdown.key_up(fn=update_dropdown, inputs=[dataset_dropdown, gr.State("dataset")], outputs=dataset_dropdown, queue=False, show_progress="hidden")
spaces_dropdown = gr.Dropdown(label="Spaces Auto-Complete", choices=[""], allow_custom_value=True)
spaces_dropdown.key_up(fn=update_dropdown, inputs=[spaces_dropdown, gr.State("space")], outputs=spaces_dropdown, queue=False, show_progress="hidden")
demo.launch()