Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
-
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
#
|
| 7 |
model = tf.keras.models.load_model('Task_Pokemon.keras')
|
| 8 |
-
|
|
|
|
| 9 |
class_names = ['Aerodactyl', 'Charizard', 'Victreebel']
|
| 10 |
|
| 11 |
def classify_image(image):
|
| 12 |
-
|
| 13 |
-
img_array = tf.keras.preprocessing.image.img_to_array(
|
| 14 |
-
img_array = tf.expand_dims(img_array, 0) #
|
| 15 |
predictions = model.predict(img_array)
|
| 16 |
predicted_class = class_names[np.argmax(predictions[0])]
|
| 17 |
confidence = np.max(predictions[0])
|
| 18 |
return predicted_class, confidence
|
| 19 |
|
| 20 |
-
image_input = gr.Image(
|
| 21 |
-
label = gr.Label(num_top_classes=3)
|
| 22 |
|
| 23 |
iface = gr.Interface(
|
| 24 |
-
fn=classify_image,
|
| 25 |
-
inputs=image_input,
|
| 26 |
outputs=label,
|
| 27 |
title='Pokémon-Bildklassifizierer',
|
| 28 |
description='Lade ein Bild von Aerodactyl, Charizard oder Victreebel hoch. Unser Klassifizierer wird das Pokémon identifizieren und das Vertrauensniveau der Vorhersage anzeigen.'
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
# Laden Sie Ihr benutzerdefiniertes Regressionsmodell
|
| 6 |
model = tf.keras.models.load_model('Task_Pokemon.keras')
|
| 7 |
+
|
| 8 |
+
# Klassennamen, sollten Ihrem Dataset entsprechen
|
| 9 |
class_names = ['Aerodactyl', 'Charizard', 'Victreebel']
|
| 10 |
|
| 11 |
def classify_image(image):
|
| 12 |
+
img_pil = image.resize((160, 160)) # Definieren der Größe der Bilder
|
| 13 |
+
img_array = tf.keras.preprocessing.image.img_to_array(img_pil)
|
| 14 |
+
img_array = tf.expand_dims(img_array, 0) # Erstellen eines Batches
|
| 15 |
predictions = model.predict(img_array)
|
| 16 |
predicted_class = class_names[np.argmax(predictions[0])]
|
| 17 |
confidence = np.max(predictions[0])
|
| 18 |
return predicted_class, confidence
|
| 19 |
|
| 20 |
+
image_input = gr.inputs.Image()
|
| 21 |
+
label = gr.outputs.Label(num_top_classes=3)
|
| 22 |
|
| 23 |
iface = gr.Interface(
|
| 24 |
+
fn=classify_image,
|
| 25 |
+
inputs=image_input,
|
| 26 |
outputs=label,
|
| 27 |
title='Pokémon-Bildklassifizierer',
|
| 28 |
description='Lade ein Bild von Aerodactyl, Charizard oder Victreebel hoch. Unser Klassifizierer wird das Pokémon identifizieren und das Vertrauensniveau der Vorhersage anzeigen.'
|