Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
+
from fastai.learner import load_learner
|
4 |
+
import os
|
5 |
+
|
6 |
+
TOKEN = os.environ["token"]
|
7 |
+
REPO_ID = "42digital/deepfashion_classification_vit-large-patch14-clip-336"
|
8 |
+
FILENAME = "model.pkl"
|
9 |
+
|
10 |
+
learner = load_learner(
|
11 |
+
hf_hub_download(repo_id=REPO_ID, filename=FILENAME, token=TOKEN)
|
12 |
+
)
|
13 |
+
|
14 |
+
def predict(img):
|
15 |
+
_, _, probs = learner.predict(img)
|
16 |
+
probs = [float(p) for p in probs.detach()]
|
17 |
+
preds = {k: v for k, v in zip(learner.dls.vocab, probs)}
|
18 |
+
return preds
|
19 |
+
|
20 |
+
gr.Interface(fn=predict,
|
21 |
+
inputs=gr.Image(type="numpy"),
|
22 |
+
outputs=gr.Label(num_top_classes=4),
|
23 |
+
examples=[]).launch()
|