Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,36 @@
|
|
1 |
-
import
|
2 |
import tensorflow as tf
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
|
6 |
-
#
|
7 |
model_path = "kia_pokemon_keras_model.h5"
|
8 |
model = tf.keras.models.load_model(model_path)
|
9 |
|
10 |
-
# Pokémon
|
11 |
-
labels = [
|
|
|
|
|
12 |
|
13 |
def predict_pokemon(image):
|
14 |
-
# Preprocess image
|
15 |
-
image = Image.fromarray(np.array(image).astype('uint8')) # Convert to PIL image
|
16 |
-
image = image.resize((224, 224)) # Resize image to 224x224
|
17 |
-
image = np.array(image)
|
18 |
-
image = np.expand_dims(image, axis=0) # Add batch dimension
|
19 |
-
|
20 |
# Predict
|
21 |
predictions = model.predict(image)
|
22 |
prediction = np.argmax(predictions, axis=1)[0]
|
23 |
confidence = np.max(predictions)
|
24 |
-
|
25 |
-
#
|
26 |
-
result = f"Predicted Pokémon: {labels[prediction]} with confidence: {confidence:.2f}
|
27 |
return result
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
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 |
# Predict
|
17 |
predictions = model.predict(image)
|
18 |
prediction = np.argmax(predictions, axis=1)[0]
|
19 |
confidence = np.max(predictions)
|
20 |
+
|
21 |
+
# Vorbereiten der Ausgabe
|
22 |
+
result = f"Predicted Pokémon: {labels[prediction]} with confidence: {confidence:.2f}"
|
23 |
return result
|
24 |
|
25 |
+
# Erstellen der Gradio-Oberfläche
|
26 |
+
input_image = gr.Image()
|
27 |
+
output_label = gr.Label()
|
28 |
+
interface = gr.Interface(fn=predict_pokemon,
|
29 |
+
inputs=input_image,
|
30 |
+
outputs=output_label,
|
31 |
+
examples=["images/bulbasaur.png", "images/charmander.png", "images/squirtle.png"],
|
32 |
+
title="Pokémon Classifier",
|
33 |
+
description="Drag and drop an image or select an example below to predict the Pokémon.")
|
34 |
+
|
35 |
+
# Interface starten
|
36 |
+
interface.launch()
|