Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,44 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import numpy as np
|
3 |
-
from tensorflow.keras.preprocessing import image
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
x =
|
17 |
-
x
|
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 |
-
st.write("
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.preprocessing import image
|
4 |
+
import tensorflow as tf
|
5 |
+
|
6 |
+
# Lade das gespeicherte Modell
|
7 |
+
model = tf.keras.models.load_model("pokemon_classification_model_xception_v2.keras")
|
8 |
+
|
9 |
+
# Setze die Bildabmessungen
|
10 |
+
img_height, img_width = 299, 299 # Eingabegröße für Xception
|
11 |
+
|
12 |
+
# Definiere eine Funktion zur Vorhersage und Rückgabe des Labels und der Wahrscheinlichkeit
|
13 |
+
def predict_label_and_probability(image_path):
|
14 |
+
# Lade das Bild und passe es an die Eingabegröße des Modells an
|
15 |
+
img = image.load_img(image_path, target_size=(img_height, img_width))
|
16 |
+
x = image.img_to_array(img)
|
17 |
+
x = np.expand_dims(x, axis=0)
|
18 |
+
x /= 255. # Skalieren der Bildpixel
|
19 |
+
|
20 |
+
# Vorhersage mit dem Modell
|
21 |
+
preds = model.predict(x)
|
22 |
+
class_idx = np.argmax(preds[0])
|
23 |
+
|
24 |
+
# Mappe Klassenindizes auf Klassennamen
|
25 |
+
class_labels = {0: 'Abra', 1: 'Butterfree', 2: 'Eevee'}
|
26 |
+
predicted_class = class_labels[class_idx]
|
27 |
+
|
28 |
+
# Gib das vorhergesagte Label und die Wahrscheinlichkeit zurück
|
29 |
+
probability = preds[0][class_idx]
|
30 |
+
return predicted_class, probability
|
31 |
+
|
32 |
+
# Streamlit App
|
33 |
+
st.title("Pokémon Classification")
|
34 |
+
|
35 |
+
uploaded_file = st.file_uploader("Choose a Pokémon image...", type="jpg")
|
36 |
+
|
37 |
+
if uploaded_file is not None:
|
38 |
+
# Zeige das hochgeladene Bild
|
39 |
+
st.image(uploaded_file, caption='Uploaded Pokémon Image.', use_column_width=True)
|
40 |
+
|
41 |
+
# Führe die Vorhersage durch und zeige das Ergebnis
|
42 |
+
label, probability = predict_label_and_probability(uploaded_file)
|
43 |
+
st.write("Prediction:", label)
|
44 |
+
st.write("Probability:", probability)
|