Spaces:
Sleeping
Sleeping
Update app.py
#1
by
heinini2
- opened
app.py
CHANGED
|
@@ -1,27 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
from
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
# Modell
|
| 7 |
-
|
| 8 |
|
| 9 |
-
def classify_image(image):
|
| 10 |
-
image = image.resize((224, 224)) # Bild auf passende Größe bringen
|
| 11 |
-
image = img_to_array(image) # Bild in Array umwandeln
|
| 12 |
-
image = np.expand_dims(image, axis=0) # Dimension hinzufügen
|
| 13 |
-
image /= 255.0 # Normalisierung
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
return {classes[i]: float(prediction[0][i]) for i in range(4)} # Wahrscheinlichkeiten zurückgeben
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
iface = gr.Interface(
|
| 20 |
-
fn=
|
| 21 |
-
inputs=gr.inputs.Image(shape=(224, 224)),
|
| 22 |
-
outputs=gr.outputs.Label(num_top_classes=4),
|
| 23 |
title="Pokémon Classifier",
|
| 24 |
description="Upload an image of a Pokémon and see the model classify it!"
|
| 25 |
)
|
| 26 |
|
|
|
|
| 27 |
iface.launch()
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
# Lade dein Modell
|
| 7 |
+
model_path = "your_pokemon_model.keras"
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Klassen Labels für deine vier Pokémon
|
| 11 |
+
labels = ['Squirtle', 'Pikachu', 'Charizard', 'Butterfree']
|
|
|
|
| 12 |
|
| 13 |
+
def predict_pokemon(image):
|
| 14 |
+
# Bildvorverarbeitung
|
| 15 |
+
image = Image.fromarray(image.astype('uint8'), 'RGB')
|
| 16 |
+
image = image.resize((224, 224)) # Anpassen der Bildgröße an das Modell
|
| 17 |
+
image = np.array(image) / 255.0 # Normalisieren der Pixelwerte
|
| 18 |
+
|
| 19 |
+
# Bild in das Modell einspeisen und Vorhersage treffen
|
| 20 |
+
prediction = model.predict(np.expand_dims(image, axis=0))
|
| 21 |
+
confidences = {labels[i]: float(np.round(prediction[0][i], 2)) for i in range(len(labels))}
|
| 22 |
+
return confidences
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# Gradio Interface definieren
|
| 26 |
iface = gr.Interface(
|
| 27 |
+
fn=predict_pokemon,
|
| 28 |
+
inputs=gr.inputs.Image(shape=(224, 224), image_mode='RGB', tool='editor'), # Eingabe als Bild
|
| 29 |
+
outputs=gr.outputs.Label(num_top_classes=4), # Zeige die Top-4 Vorhersagen
|
| 30 |
title="Pokémon Classifier",
|
| 31 |
description="Upload an image of a Pokémon and see the model classify it!"
|
| 32 |
)
|
| 33 |
|
| 34 |
+
# Starte die Gradio-Schnittstelle
|
| 35 |
iface.launch()
|
| 36 |
+
|
| 37 |
+
|