CoolFace
Apppublic

osanseviero/llama-classifiers

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
app.py33 linesDownload Raw Back to root
1import gradio as gr2 3from huggingface_hub import HfApi, hf_hub_download4from transformers import pipeline5 6def get_model_ids():7    api = HfApi()8    models = api.list_models(filter="llama-leaderboard")9    model_ids = [x.modelId for x in models]10    return model_ids11    12models = {}13for model_id in get_model_ids():14  models[model_id] = pipeline("image-classification", model=model_id)15    16def predict(img, model_id):17  preds =  models[model_id](img)18  res = {}19  for pred in preds:20    res[pred["label"]] = pred["score"]21  return res22  23gr.Interface(24  fn=predict, 25   inputs=[26     gr.inputs.Image(type="pil"),27     gr.inputs.Dropdown(get_model_ids()),28   ],29   outputs=gr.outputs.Label(num_top_classes=3),30   examples=[["llama.jpg", "osanseviero/llama-or-potato"], 31     ["potato.jpg", "osanseviero/llama-or-potato"],32     ["horse.jpg", "osanseviero/llama-horse-zebra"]]33).launch()