File size: 1,302 Bytes
4ee79c9
e426391
 
4ee79c9
e426391
4ee79c9
 
 
 
 
 
 
7095d4d
4ee79c9
 
 
 
 
 
 
 
 
 
2ce38cd
7b64e42
1add3b8
40b01ce
a97d993
4ee79c9
 
 
 
 
 
2ce38cd
 
 
4ee79c9
 
 
15c3d25
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
from fastai.vision.all import *
import gradio as gr

# Define the list of 1st generation Pokémon class names

def get_x(item):
    return item['image']  # Access images directly

def get_y(item):
    return class_names[item['labels']]  # Map label index to class name

# Load the model
learn = load_learner('poke_model.pkl')

# Categories are derived from the vocabulary of the dataloader used during training
categories = learn.dls.vocab  # These are the class labels used in the trained model

# Define the function for prediction
def classify_pokemon(img):
    pred, idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))

# Gradio interface setup
title = "Pokémon first gen classifier"
description = "Based on the famous scene (Who's that Pokémon) of the Pokémon TV show, this neural network accurately classifies a Pokémon image."
image = gr.Image(type='pil')  # Image size should match your training data size (e.g., 128x128)
label = gr.Label()
examples =  ['zapdos.jpg']

# Set up Gradio interface
intf = gr.Interface(
    fn=classify_pokemon,
    inputs=image,
    outputs=label,
    examples=examples,
    title=title,
    description=description
)

# Launch the app
intf.launch(inline=False)  # share=True allows you to share the interface via a public link