de-Rodrigo commited on
Commit
4948600
·
1 Parent(s): c3a906e

Filter Dropdown Models Properly

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -1,17 +1,17 @@
1
  from typing import List
2
  import gradio as gr
3
- from transformers import AutoModel, AutoTokenizer
4
  from huggingface_hub import list_models
5
 
6
- def get_collection_models(collection_name: str) -> List[str]:
7
  """Get a list of models from a specific Hugging Face collection."""
8
- models = list_models(author="de-Rodrigo",
9
- filter=f"collections:{collection_name}")
10
- models_nofilter = list_models(author="de-Rodrigo")
11
- print("")
12
- print(models_nofilter)
13
- print("")
14
- model_names = [model.modelId for model in models]
15
  return model_names
16
 
17
  def load_model(model_name: str):
@@ -28,19 +28,18 @@ def process_input(text: str, model_name: str) -> str:
28
  return f"Processed output with {model_name}"
29
 
30
  # Create Gradio interface
31
- def create_interface(collection_name: str):
32
  iface = gr.Interface(
33
  fn=process_input,
34
  inputs=[
35
  gr.Textbox(lines=2, placeholder="Enter some text", label="Input Text"),
36
- gr.Dropdown(choices=get_collection_models(collection_name), label="Select Model")
37
  ],
38
  outputs=gr.Textbox(label="Model Output"),
39
- title="Hugging Face Model Selector from Collection",
40
- description=f"Select a model from the '{collection_name}'.")
41
  return iface
42
 
43
  # Specify the name of your collection
44
- collection_name = "VrDU-Doctor"
45
- iface = create_interface(collection_name)
46
  iface.launch()
 
1
  from typing import List
2
  import gradio as gr
3
+ # from transformers import AutoModel, AutoTokenizer
4
  from huggingface_hub import list_models
5
 
6
+ def get_collection_models(tag: str) -> List[str]:
7
  """Get a list of models from a specific Hugging Face collection."""
8
+ models = list_models(author="de-Rodrigo")
9
+
10
+ model_names = []
11
+ for model in models:
12
+ if tag in model.tags:
13
+ model_names.append(model.modelId)
14
+
15
  return model_names
16
 
17
  def load_model(model_name: str):
 
28
  return f"Processed output with {model_name}"
29
 
30
  # Create Gradio interface
31
+ def create_interface(tag: str):
32
  iface = gr.Interface(
33
  fn=process_input,
34
  inputs=[
35
  gr.Textbox(lines=2, placeholder="Enter some text", label="Input Text"),
36
+ gr.Dropdown(choices=get_collection_models(tag), label="Select Model")
37
  ],
38
  outputs=gr.Textbox(label="Model Output"),
39
+ title="Hugging Face Model Selector from Collection")
 
40
  return iface
41
 
42
  # Specify the name of your collection
43
+ filter_tag = "saliency-merit"
44
+ iface = create_interface(filter_tag)
45
  iface.launch()