victor commited on
Commit
4ee79c9
1 Parent(s): a57d089

changed scrip and added model

Browse files
Files changed (2) hide show
  1. app.py +63 -5
  2. poke_model.pkl +3 -0
app.py CHANGED
@@ -1,8 +1,66 @@
1
- #victor
2
  import gradio as gr
3
 
4
- def greet(name):
5
- return "Hello " + name + "!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
8
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
  import gradio as gr
3
 
4
+ # Define the list of 1st generation Pokémon class names
5
+ class_names = [
6
+ "Bulbasaur", "Ivysaur", "Venusaur",
7
+ "Charmander", "Charmeleon", "Charizard",
8
+ "Squirtle", "Wartortle", "Blastoise",
9
+ "Caterpie", "Metapod", "Butterfree",
10
+ "Weedle", "Kakuna", "Beedrill",
11
+ "Pidgey", "Pidgeotto", "Pidgeot",
12
+ "Rattata", "Raticate", "Spearow",
13
+ "Fearow", "Ekans", "Arbok",
14
+ "Psyduck", "Golduck", "Machop",
15
+ "Machoke", "Machamp", "Bellsprout",
16
+ "Weepinbell", "Victreebel", "Tentacool",
17
+ "Tentacruel", "Geodude", "Graveler",
18
+ "Golem", "Ponyta", "Rapidash",
19
+ "Magnemite", "Magneton", "Krabby",
20
+ "Kingler", "Exeggcute", "Exeggutor",
21
+ "Cubone", "Marowak", "Hitmonlee",
22
+ "Hitmonchan", "Lickitung", "Koffing",
23
+ "Weezing", "Rhyhorn", "Rhydon",
24
+ "Chansey", "Tangela", "Kangaskhan",
25
+ "Horsea", "Seadra", "Goldeen",
26
+ "Seaking", "Staryu", "Starmie",
27
+ "Mr. Mime", "Scyther", "Jynx",
28
+ "Electabuzz", "Magmar", "Pinsir",
29
+ "Tauros", "Magikarp", "Gyarados",
30
+ "Lapras", "Ditto", "Eevee",
31
+ "Vaporeon", "Jolteon", "Flareon",
32
+ "Porygon", "Omanyte", "Omastar",
33
+ "Kabuto", "Kabutops", "Aerodactyl",
34
+ "Mew", "Mewtwo"
35
+ ]
36
 
37
+ def get_x(item):
38
+ return item['image'] # Access images directly
39
+
40
+ def get_y(item):
41
+ return class_names[item['labels']] # Map label index to class name
42
+
43
+ # Load the model
44
+ learn = load_learner('poke_model.pkl', cpu=False) # Ensure correct path to poke_model.pkl
45
+
46
+ # Categories are derived from the vocabulary of the dataloader used during training
47
+ categories = learn.dls.vocab # These are the class labels used in the trained model
48
+
49
+ # Define the function for prediction
50
+ def classify_pokemon(img):
51
+ pred, idx, probs = learn.predict(img)
52
+ return dict(zip(categories, map(float, probs)))
53
+
54
+ # Gradio interface setup
55
+ image = gr.inputs.Image(shape=(128, 128)) # Image size should match your training data size (e.g., 128x128)
56
+ label = gr.outputs.Label()
57
+
58
+ # Set up Gradio interface
59
+ intf = gr.Interface(
60
+ fn=classify_pokemon,
61
+ inputs=image,
62
+ outputs=label,
63
+ )
64
+
65
+ # Launch the app
66
+ intf.launch(share=True) # share=True allows you to share the interface via a public link
poke_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df8a6e0f7870af2eb90b90b464009dd87dd703b2f99c0069346be2c234b63df1
3
+ size 87794542