File size: 1,222 Bytes
a8d302e
 
 
 
e6c21d3
a8d302e
e6c21d3
a8d302e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import keras
from keras.src.applications.densenet import preprocess_input
import numpy as np
from load_safetensors import model_load

pokedex = model_load()

with open('Pokemons.txt', 'r') as f:
  class_labels = f.read().splitlines()


def classify_pokemon(image):

  img = image.resize((224, 224))

  x = keras.utils.img_to_array(img)
  x = np.expand_dims(x, axis=0)
  x = preprocess_input(x)

  preds = pokedex.predict(x)

  top_indices = preds[0].argsort()[-3:][::-1]

  results = {class_labels[i]: float(preds[0][i]) for i in top_indices}
  return results


title = "Pokedex"
description = "Pokémon first gen classifier"

examples = [
    'examples/Pikachu.png',
    'examples/Charmander.png',
    'examples/Squirtle.png',
    'examples/Bulbasaur.png',
    'examples/Caterpie.png',
    'examples/Cloyster.png',
    'examples/Gengar.png',
    'examples/Porygon.png',
    'examples/Rapidash.png',
    'examples/Slowpoke.png',
]
intf = gr.Interface(
    fn=classify_pokemon,
    inputs=gr.Image(type='pil', label="Upload a Pokémon image"),
    outputs=gr.Label(num_top_classes=3, label="Prediction"),
    examples=examples,
    title=title,
    description=description,
)

intf.launch(inline=False)