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)