brian-xetdata commited on
Commit
ae727e3
·
1 Parent(s): 8b4f646

Using the gradio built in HubSearch component

Browse files
Files changed (2) hide show
  1. app.py +9 -2
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,10 +1,12 @@
1
  import gradio as gr
2
  from huggingface_hub import model_info, hf_hub_url
 
3
  from netron import build_netron_iframe, is_netron_file
4
 
5
  current_repo = None
6
 
7
  def repo_change(repo: str, oauth_token: str) -> dict[str, any] | None:
 
8
  global current_repo
9
  current_repo = repo
10
 
@@ -40,12 +42,17 @@ with gr.Blocks() as viewer_app:
40
  gr.LoginButton(min_width=250)
41
 
42
  with gr.Column():
43
- repo = gr.Textbox(placeholder="owner/model name (Sign in above to view private models)", label="Model Repository")
 
 
 
 
 
44
  files = gr.Dropdown(choices=[], interactive=False, label="File")
45
 
46
  viewer = gr.HTML("""<p>Enter the model ID and select the compatible model file to view the model's graph view.</p>""")
47
 
48
- repo.change(fn=repo_change, inputs=[repo], outputs=[files], trigger_mode='always_last')
49
  files.select(fn=viewer_change, inputs=[files], outputs=[viewer])
50
 
51
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from huggingface_hub import model_info, hf_hub_url
3
+ from gradio_huggingfacehub_search import HuggingfaceHubSearch
4
  from netron import build_netron_iframe, is_netron_file
5
 
6
  current_repo = None
7
 
8
  def repo_change(repo: str, oauth_token: str) -> dict[str, any] | None:
9
+ print("repo changed")
10
  global current_repo
11
  current_repo = repo
12
 
 
42
  gr.LoginButton(min_width=250)
43
 
44
  with gr.Column():
45
+ with gr.Row():
46
+ model_in = HuggingfaceHubSearch(
47
+ label="Model ID",
48
+ placeholder="Search for models on Huggingface",
49
+ search_type="model",
50
+ )
51
  files = gr.Dropdown(choices=[], interactive=False, label="File")
52
 
53
  viewer = gr.HTML("""<p>Enter the model ID and select the compatible model file to view the model's graph view.</p>""")
54
 
55
+ gr.on([model_in.submit, model_in.change], fn=repo_change, inputs=[model_in], outputs=[files], trigger_mode="always_last")
56
  files.select(fn=viewer_change, inputs=[files], outputs=[viewer])
57
 
58
  if __name__ == "__main__":
requirements.txt CHANGED
@@ -1 +1,2 @@
1
  huggingface_hub
 
 
1
  huggingface_hub
2
+ gradio_huggingfacehub_search