Spaces:
Running
Running
File size: 887 Bytes
f4ed31f caf8102 f4ed31f d3eb3e6 f4ed31f a916a7e 49aee3e f4ed31f f382990 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 28 29 30 31 32 33 |
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):
preds = models[model_id](img)
res = {}
for pred in preds:
res[pred["label"]] = pred["score"]
return res
gr.Interface(
fn=predict,
inputs=[
gr.inputs.Image(type="pil"),
gr.inputs.Dropdown(get_model_ids()),
],
outputs=gr.outputs.Label(num_top_classes=3),
examples=[["llama.jpg", "osanseviero/llama-or-potato"],
["potato.jpg", "osanseviero/llama-or-potato"],
["horse.jpg", "osanseviero/llama-horse-zebra"]]
).launch() |