Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ def predict_pokemon_type(uploaded_file):
|
|
9 |
if uploaded_file is None:
|
10 |
return "No file uploaded.", None, "No prediction"
|
11 |
|
12 |
-
model = tf.keras.models.load_model('pokemon-
|
13 |
|
14 |
# Load the image from the file path
|
15 |
with Image.open(uploaded_file) as img:
|
@@ -17,20 +17,18 @@ def predict_pokemon_type(uploaded_file):
|
|
17 |
img_array = np.array(img)
|
18 |
|
19 |
prediction = model.predict(np.expand_dims(img_array, axis=0))
|
20 |
-
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
21 |
|
22 |
-
# Identify the most confident prediction
|
23 |
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
24 |
|
25 |
return img, confidences
|
26 |
|
27 |
# Define the Gradio interface
|
28 |
iface = gr.Interface(
|
29 |
-
fn=predict_pokemon_type,
|
30 |
-
inputs=gr.File(label="Upload File"),
|
31 |
-
outputs=["image", "text"],
|
32 |
-
title="Pokemon Classifier",
|
33 |
-
description="Upload a picture of a Pokemon (preferably Cubone, Ditto, Psyduck, Snorlax, or Weedle) to see its type and confidence level. The trained model has
|
34 |
)
|
35 |
|
36 |
# Launch the interface
|
|
|
9 |
if uploaded_file is None:
|
10 |
return "No file uploaded.", None, "No prediction"
|
11 |
|
12 |
+
model = tf.keras.models.load_model('pokemon-model.keras')
|
13 |
|
14 |
# Load the image from the file path
|
15 |
with Image.open(uploaded_file) as img:
|
|
|
17 |
img_array = np.array(img)
|
18 |
|
19 |
prediction = model.predict(np.expand_dims(img_array, axis=0))
|
|
|
20 |
|
|
|
21 |
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
22 |
|
23 |
return img, confidences
|
24 |
|
25 |
# Define the Gradio interface
|
26 |
iface = gr.Interface(
|
27 |
+
fn=predict_pokemon_type,
|
28 |
+
inputs=gr.File(label="Upload File"),
|
29 |
+
outputs=["image", "text"],
|
30 |
+
title="Pokemon Classifier",
|
31 |
+
description="Upload a picture of a Pokemon (preferably Cubone, Ditto, Psyduck, Snorlax, or Weedle) to see its type and confidence level. The trained model has a test accuracy of 99.17%!"
|
32 |
)
|
33 |
|
34 |
# Launch the interface
|