add title
Browse files- app.py +38 -16
- log.csv +4 -0
- pikachu.webp +0 -0
- requirements.txt +1 -0
- rhinocorne.webp +0 -0
- tortank.png +0 -0
app.py
CHANGED
|
@@ -1,42 +1,64 @@
|
|
| 1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../pokemonclassifier.ipynb.
|
| 2 |
|
| 3 |
# %% auto 0
|
| 4 |
-
__all__ = ['modelname', 'pokemon_types', 'pokemon_types_en', '
|
| 5 |
-
'
|
| 6 |
|
| 7 |
# %% ../pokemonclassifier.ipynb 3
|
| 8 |
import pandas as pd
|
| 9 |
|
| 10 |
modelname = 'model.pkl'
|
| 11 |
|
| 12 |
-
pokemon_types = pd.read_csv("pokemongen1patch.csv"
|
| 13 |
pokemon_types_en = pokemon_types['en']
|
| 14 |
-
pokemon_types_fr = pokemon_types['fr']
|
| 15 |
|
| 16 |
-
# %% ../pokemonclassifier.ipynb
|
| 17 |
from huggingface_hub import hf_hub_download
|
| 18 |
from fastai.learner import load_learner
|
| 19 |
|
| 20 |
learn_inf = load_learner(hf_hub_download("Okkoman/PokeFace", modelname))
|
| 21 |
-
learn_inf.dls.vocab
|
| 22 |
imagespath = ''
|
| 23 |
|
| 24 |
-
# %% ../pokemonclassifier.ipynb
|
| 25 |
import gradio as gr
|
|
|
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def classify_image(img):
|
| 28 |
-
prob_threshold = 0.8
|
| 29 |
pred,pred_idx,probs = learn_inf.predict(img)
|
| 30 |
index = pokemon_types_en[pokemon_types_en == pred].index[0]
|
| 31 |
-
|
| 32 |
if probs[pred_idx] > prob_threshold:
|
| 33 |
-
return f"{
|
| 34 |
else:
|
| 35 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
label = gr.outputs.Label()
|
| 39 |
-
examples = [f"{imagespath}pikachu.webp", f"{imagespath}bulbizarre.jpg", f"{imagespath}tortank.png"]
|
| 40 |
|
| 41 |
-
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 42 |
-
intf.launch(inline=False)
|
|
|
|
| 1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../pokemonclassifier.ipynb.
|
| 2 |
|
| 3 |
# %% auto 0
|
| 4 |
+
__all__ = ['modelname', 'pokemon_types', 'pokemon_types_en', 'learn_inf', 'imagespath', 'lang', 'prob_threshold',
|
| 5 |
+
'classify_image']
|
| 6 |
|
| 7 |
# %% ../pokemonclassifier.ipynb 3
|
| 8 |
import pandas as pd
|
| 9 |
|
| 10 |
modelname = 'model.pkl'
|
| 11 |
|
| 12 |
+
pokemon_types = pd.read_csv("pokemongen1patch.csv")
|
| 13 |
pokemon_types_en = pokemon_types['en']
|
|
|
|
| 14 |
|
| 15 |
+
# %% ../pokemonclassifier.ipynb 27
|
| 16 |
from huggingface_hub import hf_hub_download
|
| 17 |
from fastai.learner import load_learner
|
| 18 |
|
| 19 |
learn_inf = load_learner(hf_hub_download("Okkoman/PokeFace", modelname))
|
|
|
|
| 20 |
imagespath = ''
|
| 21 |
|
| 22 |
+
# %% ../pokemonclassifier.ipynb 31
|
| 23 |
import gradio as gr
|
| 24 |
+
from flask import request
|
| 25 |
|
| 26 |
+
lang = 'en'
|
| 27 |
+
prob_threshold = 0.75
|
| 28 |
+
|
| 29 |
+
if request:
|
| 30 |
+
lang = request.headers.get("Accept-Language")
|
| 31 |
+
if lang == 'fr':
|
| 32 |
+
title = "# PokeFace : Quel est ce pokemon ?"
|
| 33 |
+
description = "## Un classifieur d'images pour les pokemons de 1ere génération (001-151)"
|
| 34 |
+
unknown = 'inconnu'
|
| 35 |
+
else:
|
| 36 |
+
title = "# PokeFace : What is this pokemon ?"
|
| 37 |
+
description = "## An image classifier for 1st generation pokemons (001-151)"
|
| 38 |
+
unknown = 'unknown'
|
| 39 |
+
|
| 40 |
def classify_image(img):
|
|
|
|
| 41 |
pred,pred_idx,probs = learn_inf.predict(img)
|
| 42 |
index = pokemon_types_en[pokemon_types_en == pred].index[0]
|
| 43 |
+
label = pokemon_types[lang].iloc[index]
|
| 44 |
if probs[pred_idx] > prob_threshold:
|
| 45 |
+
return f"{label} {probs[pred_idx]*100:.0f}%"
|
| 46 |
else:
|
| 47 |
+
return unknown
|
| 48 |
+
|
| 49 |
+
with gr.Blocks() as demo:
|
| 50 |
+
|
| 51 |
+
with gr.Row():
|
| 52 |
+
gr.Markdown(title)
|
| 53 |
+
with gr.Row():
|
| 54 |
+
gr.Markdown(description)
|
| 55 |
+
with gr.Row():
|
| 56 |
+
interf = gr.Interface(
|
| 57 |
+
fn=classify_image,
|
| 58 |
+
inputs=gr.inputs.Image(shape=(192,192)),
|
| 59 |
+
outputs=gr.outputs.Label(),
|
| 60 |
+
examples=imagespath,
|
| 61 |
+
allow_flagging='auto')
|
| 62 |
|
| 63 |
+
demo.launch(inline=False)
|
|
|
|
|
|
|
| 64 |
|
|
|
|
|
|
log.csv
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
input
|
| 2 |
+
pikachu.webp
|
| 3 |
+
rhinocorne.webp
|
| 4 |
+
bulbizarre.jpg
|
pikachu.webp
CHANGED
|
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
fastai>=2.0.0
|
| 2 |
pandas
|
| 3 |
|
|
|
|
| 1 |
+
flask
|
| 2 |
fastai>=2.0.0
|
| 3 |
pandas
|
| 4 |
|
rhinocorne.webp
ADDED
|
tortank.png
DELETED
|
Binary file (106 kB)
|
|
|