Update app.py
Browse files
app.py
CHANGED
@@ -17,21 +17,28 @@ labels = ['Abra', 'Cloyster', 'Dodrio']
|
|
17 |
|
18 |
# Vorhersagefunktion
|
19 |
def predict(image):
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Gradio-Interface erstellen
|
29 |
iface = gr.Interface(
|
30 |
fn=predict,
|
31 |
-
inputs=gr.Image(), #
|
32 |
outputs=gr.Label(),
|
33 |
description="Pokémon Classifier"
|
34 |
)
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
iface.launch()
|
|
|
|
17 |
|
18 |
# Vorhersagefunktion
|
19 |
def predict(image):
|
20 |
+
try:
|
21 |
+
# Bildvorverarbeitung
|
22 |
+
image = image.resize((64, 64))
|
23 |
+
image = np.array(image) / 255.0
|
24 |
+
image = np.expand_dims(image, axis=0)
|
25 |
+
|
26 |
+
# Vorhersage
|
27 |
+
predictions = model.predict(image)
|
28 |
+
confidences = {labels[i]: float(predictions[0][i]) for i in range(len(labels))}
|
29 |
+
|
30 |
+
return confidences
|
31 |
+
except Exception as e:
|
32 |
+
return str(e) # Fehlernachricht zurückgeben
|
33 |
|
34 |
# Gradio-Interface erstellen
|
35 |
iface = gr.Interface(
|
36 |
fn=predict,
|
37 |
+
inputs=gr.Image(type="pil"), # Bild als PIL-Objekt
|
38 |
outputs=gr.Label(),
|
39 |
description="Pokémon Classifier"
|
40 |
)
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
iface.launch()
|
44 |
+
|