Spaces:
Runtime error
Runtime error
File size: 2,819 Bytes
fe40805 567a6c9 fe40805 567a6c9 fe40805 567a6c9 fe40805 91461f8 fe40805 567a6c9 fe40805 |
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 |
# 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)
|