File size: 980 Bytes
b041c76
 
 
 
 
 
 
2400366
 
 
 
 
 
 
 
 
 
b041c76
 
 
 
 
 
 
a948793
 
 
 
b041c76
 
9abe2f3
 
451a2a2
b041c76
 
 
4cb0c1d
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
__all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']

# Cell
from fastai.vision.all import *
import gradio as gr
import timm

# Cell
# Check if AMPMode exists in the current fastai version
try:
    from fastai.callback.fp16 import AMPMode
except ImportError:
    # Define AMPMode if not found (you need to replace this with the actual implementation)
    class AMPMode:
        def __init__(self):
            pass

# Cell
learn = load_learner('model.pkl')

# Cell
categories = learn.dls.vocab

def classify_image(img):
    # Ensure img is transformed into a tensor in the right shape
    img = PILImage.create(img)
    pred, idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))

# Cell
image = gr.components.Image()
label = gr.components.Label()
examples = ['Maine_Coon.jpg', 'Beagle.jpg']

# Cell
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)