File size: 1,118 Bytes
55e26c5
 
 
 
 
 
 
3e73f96
 
 
55e26c5
 
 
 
3e73f96
 
55e26c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import numpy as np
from PIL import Image
from keras.models import load_model
from sklearn.preprocessing import LabelEncoder
import pickle

# das trainierte Modell und den LabelEncoder laden
model = load_model('dog_breed_classifier.h5')
with open('label_encoder.pkl', 'rb') as f:
    label_encoder = pickle.load(f)


def predict_breed(image, model, label_encoder):
    image = image.resize((128, 128))
    image = np.expand_dims(np.array(image), axis=0)
    predictions = model.predict(image)
    predicted_breed = label_encoder.inverse_transform([np.argmax(predictions)])
    return predicted_breed[0]


# Streamlit App Titel
st.title("DogID - Finde die Rasse eines Hundes heraus!")

# Bild hochladen
uploaded_file = st.file_uploader("Füge hier deinen Freund auf vier Beinen ein", type="jpg")

if uploaded_file is not None:
    # Bild anzeigen
    image = Image.open(uploaded_file)
    st.image(image, caption='Dein hochgeladenes Bild.', use_column_width=True)

    # Vorhersage treffen
    breed = predict_breed(image, model, label_encoder)
    st.write(f'Toll - Dieser Hund ist ein {breed}!')