File size: 687 Bytes
5fba393
4beb837
788fbbb
 
c151ed3
788fbbb
c151ed3
06798cf
788fbbb
c9c6eae
bf8d034
788fbbb
 
 
 
 
 
 
bf8d034
 
788fbbb
 
bf8d034
c151ed3
 
 
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
import os
from huggingface_hub import from_pretrained_fastai

import gradio as gr
from gradio.components import Image

HF_TOKEN = os.getenv("HF_TOKEN")
print(HF_TOKEN[-1:-5])
repo_id = "artificeresearch/spiritvision"
learner = from_pretrained_fastai(repo_id)
labels = learner.dls.vocab


def predict_fn(img):
    """
    :param img: img is a PIL image object
    :return: prediction and probabilities
    """
    pred, pred_idx, probs = learner.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}


gr.Interface(predict_fn,
             Image(shape=(512, 512)),
             outputs=gr.outputs.Label(num_top_classes=3),
             token=HF_TOKEN).launch()