Spaces:
Runtime error
Runtime error
Upload 9 files
Browse files- .gitattributes +1 -0
- app.py +41 -0
- examples/football65.png +3 -0
- examples/gettyimages-1202172-612x612.jpg +0 -0
- examples/gettyimages-517216508-612x612.jpg +0 -0
- examples/gettyimages-517441216-612x612.jpg +0 -0
- examples/photo-1583051663501-de1f00bd6ad4.jpeg +0 -0
- examples/photo-1687278346516-17a9f85b0252.jpeg +0 -0
- examples/rugby73.jpeg +0 -0
- examples/squashsport229.jpeg +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
examples/football65.png filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import timm
|
| 5 |
+
from huggingface_hub import login
|
| 6 |
+
from torch import no_grad, softmax, topk
|
| 7 |
+
|
| 8 |
+
MODEL_NAME = os.getenv("MODEL_NAME")
|
| 9 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 10 |
+
|
| 11 |
+
login(token=HF_TOKEN)
|
| 12 |
+
|
| 13 |
+
model = timm.create_model(f"hf_hub:{MODEL_NAME}", pretrained=True)
|
| 14 |
+
model.eval()
|
| 15 |
+
|
| 16 |
+
data_cfg = timm.data.resolve_data_config(model.pretrained_cfg)
|
| 17 |
+
transform = timm.data.create_transform(**data_cfg)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def classify_image(input):
|
| 21 |
+
inp = transform(input)
|
| 22 |
+
with no_grad():
|
| 23 |
+
output = model(inp.unsqueeze(0))
|
| 24 |
+
probabilities = softmax(output[0], dim=0)
|
| 25 |
+
values, indices = topk(probabilities, 3)
|
| 26 |
+
|
| 27 |
+
return {
|
| 28 |
+
model.pretrained_cfg["label_names"][str(id.item())].title(): prob
|
| 29 |
+
for id, prob in zip(indices, values)
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
fn=classify_image,
|
| 35 |
+
inputs=gr.Image(type="pil", sources=["upload", "clipboard"]),
|
| 36 |
+
outputs=gr.Label(num_top_classes=3),
|
| 37 |
+
allow_flagging="never",
|
| 38 |
+
examples="examples",
|
| 39 |
+
)
|
| 40 |
+
demo.queue()
|
| 41 |
+
demo.launch(debug=True)
|
examples/football65.png
ADDED
|
Git LFS Details
|
examples/gettyimages-1202172-612x612.jpg
ADDED
|
examples/gettyimages-517216508-612x612.jpg
ADDED
|
examples/gettyimages-517441216-612x612.jpg
ADDED
|
examples/photo-1583051663501-de1f00bd6ad4.jpeg
ADDED
|
examples/photo-1687278346516-17a9f85b0252.jpeg
ADDED
|
examples/rugby73.jpeg
ADDED
|
examples/squashsport229.jpeg
ADDED
|