Spaces:
Running
Running
Commit
·
f4ed31f
1
Parent(s):
a5b619b
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 4 |
+
from transformers import model
|
| 5 |
+
|
| 6 |
+
def 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_ids
|
| 11 |
+
|
| 12 |
+
models = {}
|
| 13 |
+
for model_id in get_model_ids():
|
| 14 |
+
models[model_id] = pipeline("image-classification", model=model_id)
|
| 15 |
+
|
| 16 |
+
def predict(img, model_id):
|
| 17 |
+
return models[model_id](img)
|
| 18 |
+
|
| 19 |
+
gr.Interface(
|
| 20 |
+
fn=predict,
|
| 21 |
+
inputs=[
|
| 22 |
+
gr.inputs.Image(type="pil"),
|
| 23 |
+
gradio.inputs.Dropdown(get_model_ids())
|
| 24 |
+
]
|
| 25 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
| 26 |
+
examples=["llama.jpg", "potato.jpg"]
|
| 27 |
+
).launch()
|