File size: 575 Bytes
788fbbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import requests
from huggingface_hub import from_pretrained_fastai

import gradio as gr

repo_id = "artificeresearch/spiritvision"
learner = from_pretrained_fastai(repo_id)


def predict_fn(img):
    """
    :param img: img is a PIL image object
    :return: prediction and probabilities
    """
    img = img.convert('RGB')
    prediction, _, probs = learner.predict(img)
    # print(f'{max(100 * probs):.2f}% {prediction} - {img}')
    return f'{max(100 * probs):.2f}% {prediction} - {img}'


gr.Interface(predict_fn, gr.inputs.Image(type='pil'), outputs='label').launch()