gassmdav commited on
Commit
e914fdf
1 Parent(s): 0795798

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Laden des vortrainierten Pokémon-Modells
7
+ model_path = "kia_pokemon_keras_model.h5"
8
+ model = tf.keras.models.load_model(model_path)
9
+
10
+ # Labels für den Pokémon Classifier
11
+ labels = [
12
+ 'Bulbasaur','Charmander','Squirtle'
13
+ ]
14
+
15
+ def predict_pokemon(image):
16
+ # Preprocess image
17
+ print(type(image)) # Output the type of the input image for debugging
18
+ image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
19
+ image = image.resize((224, 224)) # Resize the image to 224x224
20
+ image = np.array(image)
21
+ image = np.expand_dims(image, axis=0) # same as image[None, ...]
22
+
23
+ # Predict
24
+ predictions = model.predict(image)
25
+ prediction = np.argmax(predictions, axis=1)[0]
26
+ confidence = np.max(predictions)
27
+
28
+ # Vorbereiten der Ausgabe
29
+ result = f"Predicted Pokémon: {labels[prediction]} with confidence: {confidence:.2f}"
30
+ return result
31
+
32
+ # Erstellen der Gradio-Oberfläche
33
+ input_image = gr.Image()
34
+ output_label = gr.Label()
35
+ interface = gr.Interface(fn=predict_pokemon,
36
+ inputs=input_image,
37
+ outputs=output_label,
38
+ examples=["images/bulbasaur.png", "images/charmander.png", "images/squirtle.png"],
39
+ title="Pokémon Classifier",
40
+ description="Drag and drop an image or select an example below to predict the Pokémon.")
41
+
42
+ # Interface starten
43
+ interface.launch()