Abdellatif Abdelfattah commited on
Commit
e30c69d
1 Parent(s): 42d6d7a

initial commit

Browse files
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Pokemon Detector
3
- emoji: 🏢
4
  colorFrom: red
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 3.4.1
8
  app_file: app.py
 
1
  ---
2
  title: Pokemon Detector
3
+ emoji: 🐢
4
  colorFrom: red
5
+ colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.4.1
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import fastbook
4
+ from pathlib import Path
5
+ from fastai.vision.widgets import *
6
+
7
+ fastbook.setup_book()
8
+
9
+ examples = ['./examples/pikachu.webp', './examples/charizard.webp',
10
+ './examples/mewtwo.jpg', './examples/rayquaza.jpeg', './examples/cinderace.webp']
11
+
12
+ path = Path()
13
+ path.ls(file_exts='.pkl')
14
+ learn_inf = fastbook.load_learner(path/'pokemon-detector.pkl')
15
+
16
+ labels = learn_inf.dls.vocab
17
+
18
+ def pokemon_classifier(image):
19
+ image = fastbook.PILImage.create(image)
20
+ pred, pred_id, probs = learn_inf.predict(image)
21
+ output = {labels[i]: float(probs[i]) for i in range(len(labels))}
22
+ # limit the output to the top 5 results
23
+ output = dict(sorted(output.items(), key=lambda item: item[1], reverse=True)[:5])
24
+ return output
25
+
26
+
27
+ iface = gr.Interface(fn=pokemon_classifier, inputs="image", outputs="label", examples=examples)
28
+ iface.launch()
examples/charizard.webp ADDED
examples/cinderace.webp ADDED
examples/mewtwo.jpg ADDED
examples/pikachu.webp ADDED
examples/rayquaza.jpeg ADDED
pokemon-detector.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56036eeeb6201a7f24fcbee2f5de0c2140ca782ec7dfb6647456780e78cdbb4f
3
+ size 51544097
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastbook
2
+ gradio
3
+ pathlib
4
+ fastai