File size: 922 Bytes
4de2db6
 
 
2adf960
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4de2db6
2adf960
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'

import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np

# Modellpfad
model_path = "pokemon_classifier_model.keras"

# Modell laden
model = tf.keras.models.load_model(model_path)

# Klassenlabels (Passe diese entsprechend deinem Modell an)
labels = ['Abra', 'Cloyster', 'Dodrio']

# Vorhersagefunktion
def predict(image):
    # Bildvorverarbeitung
    image = image.resize((64, 64))
    image = np.array(image) / 255.0
    image = np.expand_dims(image, axis=0)
    predictions = model.predict(image)
    confidences = {labels[i]: float(predictions[0][i]) for i in range(len(labels))}
    return confidences

# Gradio-Interface erstellen
iface = gr.Interface(
    fn=predict, 
    inputs=gr.Image(),  # Keine shape-Parameter hier
    outputs=gr.Label(),
    description="Pokémon Classifier"
)

if __name__ == "__main__":
    iface.launch()