File size: 1,157 Bytes
6d547b8
 
 
 
 
5369008
6d547b8
 
 
5369008
 
6d547b8
5369008
 
 
 
6d547b8
5369008
 
 
 
6d547b8
5369008
 
 
 
6d547b8
5369008
 
6d547b8
5369008
6d547b8
5369008
6d547b8
5369008
 
 
 
 
 
 
 
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
39
40
41
42
43
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

# Pfad zum gespeicherten Modell
model_path = "pokemon-model_transferlearning.keras"
model = tf.keras.models.load_model(model_path)

# Definieren der Klassennamen
labels = ['Articuno', 'Bulbasaur', 'Charmander']

# Funktion zur Klassifizierung
def classify_pokemon(image):
    if image is None:
        return {"Error": "No image uploaded"}
    
    # Bildvorverarbeitung
    image = Image.fromarray(image).resize((150, 150))
    image = np.array(image) / 255.0
    image = np.expand_dims(image, axis=0)
    
    # Vorhersage
    prediction = model.predict(image)
    predicted_class = np.argmax(prediction[0])
    confidence = np.max(prediction[0])
    
    # Konfidenzwerte
    confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
    
    return confidences, f"Predicted: {labels[predicted_class]}, Confidence: {confidence:.2f}"

# Erstellen einer Gradio-Schnittstelle
iface = gr.Interface(
    fn=classify_pokemon,
    inputs=gr.Image(),
    outputs=["label", "text"],
    live=True
)

# Starten der Schnittstelle
iface.launch()