File size: 777 Bytes
1d0fa91
 
 
 
 
 
 
 
594fd54
1d0fa91
 
 
 
 
 
 
 
 
 
 
 
 
594fd54
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from huggingface_hub import hf_hub_download
from fastai.learner import load_learner
import os

TOKEN = os.environ["token"]
REPO_ID = "42digital/deepfashion_classification_vit-large-patch14-clip-336"
FILENAME = "model.pkl"
EXAMPLES = ["dress.jpg", "hoodie.jpg", "joggers.jpg", "jumpsuit.jpg", "shorts.jpg", "tee.jpg"]

learner = load_learner(
    hf_hub_download(repo_id=REPO_ID, filename=FILENAME, token=TOKEN)
)

def predict(img):
    _, _, probs = learner.predict(img)
    probs = [float(p) for p in probs.detach()]
    preds = {k: v for k, v in zip(learner.dls.vocab, probs)}
    return preds

gr.Interface(fn=predict, 
             inputs=gr.Image(type="numpy"),
             outputs=gr.Label(num_top_classes=5),
             examples=EXAMPLES).launch()