Spaces:
Runtime error
Runtime error
# AUTOGENERATED! DO NOT EDIT! File to edit: pokemonScript.ipynb. | |
# %% auto 0 | |
__all__ = ['textLabels', 'learn', 'categories', 'image', 'label', 'examples', 'intf', 'get_x', 'get_y', 'classify_img'] | |
# %% pokemonScript.ipynb 3 | |
from fastai.vision.all import * | |
import gradio as gr | |
#dependencies | |
textLabels = ['Porygon', 'Goldeen', 'Hitmonlee', 'Hitmonchan', 'Gloom', 'Aerodactyl', 'Mankey', 'Seadra', 'Gengar', 'Venonat', 'Articuno', 'Seaking', 'Dugtrio', 'Machop', 'Jynx', 'Oddish', 'Dodrio', 'Dragonair', 'Weedle', 'Golduck', 'Flareon', 'Krabby', 'Parasect', 'Ninetales', 'Nidoqueen', 'Kabutops', 'Drowzee', 'Caterpie', 'Jigglypuff', 'Machamp', 'Clefairy', 'Kangaskhan', 'Dragonite', 'Weepinbell', 'Fearow', 'Bellsprout', 'Grimer', 'Nidorina', 'Staryu', 'Horsea', 'Electabuzz', 'Dratini', 'Machoke', 'Magnemite', 'Squirtle', 'Gyarados', 'Pidgeot', 'Bulbasaur', 'Nidoking', 'Golem', 'Dewgong', 'Moltres', 'Zapdos', 'Poliwrath', 'Vulpix', 'Beedrill', 'Charmander', 'Abra', 'Zubat', 'Golbat', 'Wigglytuff', 'Charizard', 'Slowpoke', 'Poliwag', 'Tentacruel', 'Rhyhorn', 'Onix', 'Butterfree', 'Exeggcute', 'Sandslash', 'Pinsir', 'Rattata', 'Growlithe', 'Haunter', 'Pidgey', 'Ditto', 'Farfetchd', 'Pikachu', 'Raticate', 'Wartortle', 'Vaporeon', 'Cloyster', 'Hypno', 'Arbok', 'Metapod', 'Tangela', 'Kingler', 'Exeggutor', 'Kadabra', 'Seel', 'Voltorb', 'Chansey', 'Venomoth', 'Ponyta', 'Vileplume', 'Koffing', 'Blastoise', 'Tentacool', 'Lickitung', 'Paras', 'Clefable', 'Cubone', 'Marowak', 'Nidorino', 'Jolteon', 'Muk', 'Magikarp', 'Slowbro', 'Tauros', 'Kabuto', 'Spearow', 'Sandshrew', 'Eevee', 'Kakuna', 'Omastar', 'Ekans', 'Geodude', 'Magmar', 'Snorlax', 'Meowth', 'Pidgeotto', 'Venusaur', 'Persian', 'Rhydon', 'Starmie', 'Charmeleon', 'Lapras', 'Alakazam', 'Graveler', 'Psyduck', 'Rapidash', 'Doduo', 'Magneton', 'Arcanine', 'Electrode', 'Omanyte', 'Poliwhirl', 'Mew', 'Alolan Sandslash', 'Mewtwo', 'Weezing', 'Gastly', 'Victreebel', 'Ivysaur', 'MrMime', 'Shellder', 'Scyther', 'Diglett', 'Primeape', 'Raichu'] | |
textLabels.sort() # important for gradio to get the labels in the right order | |
def get_x(o): return o['image_file_path'] # get the image path | |
def get_y(o): return textLabels[o['labels']] # get the label | |
# %% pokemonScript.ipynb 5 | |
learn = load_learner('pokemonClassifier.pkl') | |
# %% pokemonScript.ipynb 7 | |
categories = textLabels | |
def classify_img(img): | |
img = PILImage.create(img) | |
pred,pred_idx,probs = learn.predict(img) | |
return dict(zip(categories, map(float, probs))) | |
# %% pokemonScript.ipynb 9 | |
image = gr.inputs.Image(shape=(224,224)) | |
label = gr.outputs.Label(num_top_classes=3) | |
examples = [ | |
'charizard.png', | |
'cubone.jpeg', | |
'garydos.webp', | |
'charizard.jpeg' | |
] | |
intf = gr.Interface(inputs=image, outputs=label, fn=classify_img, examples=examples) | |
intf.launch(inline=False) | |