pokemon / app.py
grobram1's picture
Update app.py
7a639d0 verified
raw
history blame
1.11 kB
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):
try:
# Bildvorverarbeitung
image = image.resize((150, 150)) # Bild auf 150x150 skalieren
image = np.array(image) / 255.0
image = np.expand_dims(image, axis=0)
# Vorhersage
predictions = model.predict(image)
confidences = {labels[i]: float(predictions[0][i]) for i in range(len(labels))}
return confidences
except Exception as e:
return str(e) # Fehlernachricht zurückgeben
# Gradio-Interface erstellen
iface = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"), # Bild als PIL-Objekt
outputs=gr.Label(),
description="Pokémon Classifier"
)
if __name__ == "__main__":
iface.launch()