File size: 1,518 Bytes
0963d32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.

# %% auto 0
__all__ = ['repo_id', 'learner', 'path', 'categories', 'title', 'description', 'article', 'image', 'label', 'examples', 'intf',
           'classify_image']

# %% app.ipynb 2
from fastai.vision.all import *
from huggingface_hub import from_pretrained_fastai
import gradio as gr

# %% app.ipynb 3
repo_id = "Jimmie/snake-image-classification"

# loading the model from huggingface_hub
learner = from_pretrained_fastai(repo_id)

# %% app.ipynb 4
path = Path('demo-images/')

# %% app.ipynb 14
categories = tuple(learner.dls.vocab)

def classify_image(img):
    pred,idx,probs = learner.predict(img)
    return dict(zip(categories, map(float, probs)))

# %% app.ipynb 16
title = "Snake Image Classification"

description = """
This demo is an ongoing iteration of a [bigger project](https://github.com/jimmiemunyi/the-snake-project) meant to classify snakes as venomous or non-venomous.

Currently, it can classify snakes into 10 genera.

The model can be found here: https://huggingface.co/Jimmie/snake-image-classification
 

Enjoy!
"""

article = "Blog posts on how the model is being trained: ."


image = gr.inputs.Image(shape=(224, 224))
label = gr.outputs.Label()
examples = list(path.ls())


intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples,
                   title = title, description = description, article = article,
                   enable_queue=True, cache_examples=False)
intf.launch(inline=False)