File size: 838 Bytes
2a42c92
 
 
 
2ff8ae9
9c4a63b
 
2a42c92
 
2ff8ae9
9c4a63b
0302379
2ff8ae9
bf02e71
2ff8ae9
 
 
 
 
 
 
 
 
 
 
179b0f6
2ff8ae9
 
 
 
 
 
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
import subprocess
import sys

subprocess.check_call([sys.executable, "-m", "pip", "install", "fastai"])
from fastai.vision.all import *
import gradio as gr

__all__ = ['is_cat', 'label', 'image', 'intf', 'examples', 'categories', 'learn']

def is_cat(x): return x[0].isupper()

learn = load_learner('my_model.pkl')

categories = ('Healthy Fungi', 'Poisonous Fungi')

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

from gradio.components import Image, Label

label = Label()
image = Image() #shape = (192, 192)
examples=[
    "healthy_fungi.jpg", "Death-cap-mushroom.jpg"]


intf = gr.Interface(fn = classify_image, inputs = image, outputs = label, examples = examples)

# Launch the web interface with the image and label components
intf.launch(inline = False)