Spaces:
Sleeping
Sleeping
import os | |
from huggingface_hub import from_pretrained_fastai | |
import gradio as gr | |
repo_id = "artificeresearch/spiritvision" | |
learner = from_pretrained_fastai(repo_id) | |
labels = learner.dls.vocab | |
HF_TOKEN = os.environ.get("HF_TOKEN") | |
def predict_fn(img): | |
""" | |
:param img: img is a PIL image object | |
:return: prediction and probabilities | |
""" | |
img = img.convert('RGB') | |
# print(f'{max(100 * probs):.2f}% {prediction} - {img}') | |
pred, pred_idx, probs = learner.predict(img) | |
return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
gr.Interface(predict_fn, | |
gr.inputs.Image(type='pil', shape=(512, 512)), | |
outputs=gr.outputs.Label(num_top_classes=3), token=HF_TOKEN).launch() | |