# AUTOGENERATED! DO NOT EDIT! File to edit: ../pokemonclassifier.ipynb. # %% auto 0 __all__ = ['modelname', 'pokemon_types', 'pokemon_types_en', 'pokemon_types_fr', 'learn_inf', 'imagespath', 'image', 'label', 'examples', 'intf', 'classify_image'] # %% ../pokemonclassifier.ipynb 3 import pandas as pd modelname = 'model.pkl' pokemon_types = pd.read_csv("pokemongen1patch.csv", nrows=20) pokemon_types_en = pokemon_types['en'] pokemon_types_fr = pokemon_types['fr'] # %% ../pokemonclassifier.ipynb 24 from huggingface_hub import hf_hub_download from fastai.learner import load_learner learn_inf = load_learner(hf_hub_download("Okkoman/PokeFace", modelname)) learn_inf.dls.vocab imagespath = '' # %% ../pokemonclassifier.ipynb 29 import gradio as gr def classify_image(img): prob_threshold = 0.8 pred,pred_idx,probs = learn_inf.predict(img) index = pokemon_types_en[pokemon_types_en == pred].index[0] pred_fr = pokemon_types_fr.iloc[index] if probs[pred_idx] > prob_threshold: return f"{pred}(en) - {pred_fr}(fr) - {probs[pred_idx]*100:.0f}%" else: return 'unknown' image = gr.inputs.Image(shape=(192,192)) label = gr.outputs.Label() examples = [f"{imagespath}pikachu.webp", f"{imagespath}bulbizarre.jpg", f"{imagespath}tortank.png"] intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) intf.launch(inline=False)