Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
from tensorflow.keras.preprocessing import image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Modell laden
|
7 |
+
model = tf.keras.models.load_model('pokemon_classifier_model.keras')
|
8 |
+
|
9 |
+
# Klassenlabels
|
10 |
+
class_names = ['Bisasam', 'Schiggy', 'Glumanda']
|
11 |
+
|
12 |
+
# Vorhersagefunktion
|
13 |
+
def predict(img):
|
14 |
+
img = img.resize((224, 224))
|
15 |
+
img_array = np.array(img)
|
16 |
+
img_array = np.expand_dims(img_array, axis=0)
|
17 |
+
img_array = tf.keras.applications.vgg16.preprocess_input(img_array)
|
18 |
+
|
19 |
+
predictions = model.predict(img_array)
|
20 |
+
score = tf.nn.softmax(predictions[0])
|
21 |
+
|
22 |
+
return {class_names[i]: float(score[i]) for i in range(3)}
|
23 |
+
|
24 |
+
# Gradio Interface erstellen
|
25 |
+
image_input = gr.inputs.Image(type='pil')
|
26 |
+
label_output = gr.outputs.Label(num_top_classes=3)
|
27 |
+
|
28 |
+
gr.Interface(fn=predict, inputs=image_input, outputs=label_output,
|
29 |
+
title="Pokémon Classifier",
|
30 |
+
description="Laden Sie ein Bild hoch, um das Pokémon zu klassifizieren.").launch()
|