Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,27 +3,33 @@ import tensorflow as tf
|
|
3 |
from tensorflow.keras.preprocessing import image
|
4 |
import numpy as np
|
5 |
|
6 |
-
# Modell laden
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
# Klassenlabels
|
10 |
class_names = ['Bisasam', 'Schiggy', 'Glumanda']
|
11 |
|
12 |
# Vorhersagefunktion
|
13 |
def predict(img):
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
|
|
|
|
23 |
|
24 |
# Gradio Interface erstellen
|
25 |
-
image_input = gr.
|
26 |
-
label_output = gr.
|
27 |
|
28 |
gr.Interface(fn=predict, inputs=image_input, outputs=label_output,
|
29 |
title="Pokémon Classifier",
|
|
|
3 |
from tensorflow.keras.preprocessing import image
|
4 |
import numpy as np
|
5 |
|
6 |
+
# Modell laden mit Fehlerbehandlung
|
7 |
+
try:
|
8 |
+
model = tf.keras.models.load_model('pokemon_classifier_model.keras')
|
9 |
+
except Exception as e:
|
10 |
+
print(f"Fehler beim Laden des Modells: {e}")
|
11 |
|
12 |
# Klassenlabels
|
13 |
class_names = ['Bisasam', 'Schiggy', 'Glumanda']
|
14 |
|
15 |
# Vorhersagefunktion
|
16 |
def predict(img):
|
17 |
+
try:
|
18 |
+
img = img.resize((224, 224))
|
19 |
+
img_array = np.array(img)
|
20 |
+
img_array = np.expand_dims(img_array, axis=0)
|
21 |
+
img_array = tf.keras.applications.vgg16.preprocess_input(img_array)
|
22 |
|
23 |
+
predictions = model.predict(img_array)
|
24 |
+
score = tf.nn.softmax(predictions[0])
|
25 |
|
26 |
+
return {class_names[i]: float(score[i]) for i in range(3)}
|
27 |
+
except Exception as e:
|
28 |
+
return {"Fehler": str(e)}
|
29 |
|
30 |
# Gradio Interface erstellen
|
31 |
+
image_input = gr.Image(type='pil')
|
32 |
+
label_output = gr.Label(num_top_classes=3)
|
33 |
|
34 |
gr.Interface(fn=predict, inputs=image_input, outputs=label_output,
|
35 |
title="Pokémon Classifier",
|