File size: 680 Bytes
f4ed31f
 
 
caf8102
f4ed31f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49aee3e
 
f4ed31f
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr

from huggingface_hub import HfApi, hf_hub_download
from transformers import pipeline

def get_model_ids():
    api = HfApi()
    models = api.list_models(filter="llama-leaderboard")
    model_ids = [x.modelId for x in models]
    return model_ids
    
models = {}
for model_id in get_model_ids():
  models[model_id] = pipeline("image-classification", model=model_id)
    
def predict(img, model_id):
  return models[model_id](img)
  
gr.Interface(
  fn=predict, 
   inputs=[
     gr.inputs.Image(type="pil"),
     gradio.inputs.Dropdown(get_model_ids()),
   ],
   outputs=gr.outputs.Label(num_top_classes=3),
   examples=["llama.jpg", "potato.jpg"]
).launch()