Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,32 +3,40 @@ import tensorflow as tf
|
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
|
6 |
-
#
|
7 |
-
model_path = "
|
8 |
-
|
9 |
-
#model.load_weights(model_path)
|
10 |
model = tf.keras.models.load_model(model_path)
|
11 |
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
def predict_regression(image):
|
16 |
# Preprocess image
|
17 |
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
18 |
-
image = image.resize((
|
19 |
image = np.array(image)
|
20 |
-
|
|
|
21 |
# Predict
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
#
|
27 |
-
input_image = gr.Image()
|
28 |
-
output_text = gr.Textbox(label="Predicted Value")
|
29 |
-
interface = gr.Interface(fn=predict_regression,
|
30 |
-
inputs=input_image,
|
31 |
-
outputs=gr.Label(),
|
32 |
-
examples=["images/0.jpeg", "images/1.jpeg", "images/2.jpeg", "images/5.jpeg"],
|
33 |
-
description="A simple mlp classification model for image classification using the mnist dataset.")
|
34 |
interface.launch()
|
|
|
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 |
+
'Balastoise','Charizard','Venusaur'
|
13 |
+
]
|
14 |
|
15 |
+
def predict_pokemon(image):
|
|
|
16 |
# Preprocess image
|
17 |
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
18 |
+
image = image.resize((299, 299))
|
19 |
image = np.array(image)
|
20 |
+
image = np.expand_dims(image, axis=0) # same as image[None, ...]
|
21 |
+
|
22 |
# Predict
|
23 |
+
predictions = model.predict(image)
|
24 |
+
prediction = np.argmax(predictions, axis=1)[0]
|
25 |
+
confidence = np.max(predictions)
|
26 |
+
|
27 |
+
# Vorbereiten der Ausgabe
|
28 |
+
result = f"Predicted Pokémon: {labels[prediction]} with confidence: {confidence:.2f}"
|
29 |
+
return result
|
30 |
+
|
31 |
+
# Erstellen der Gradio-Oberfläche
|
32 |
+
input_image = gr.Image()
|
33 |
+
output_label = gr.Label()
|
34 |
+
interface = gr.Interface(fn=predict_pokemon,
|
35 |
+
inputs=input_image,
|
36 |
+
outputs=output_label,
|
37 |
+
examples=["Blastoise.jpg", "Charizard.png", "Venusaur.png"],
|
38 |
+
title="Pokémon Classifier",
|
39 |
+
description="Drag and drop an image or select an example below to predict the Pokémon.")
|
40 |
|
41 |
+
# Interface starten
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
interface.launch()
|