Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,42 +11,29 @@ model = tf.keras.models.load_model(model_path)
|
|
| 11 |
|
| 12 |
labels = ['Abra', 'Ditto', 'Gengar']
|
| 13 |
|
| 14 |
-
def
|
| 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 |
-
prediction = model.predict(image[None, ...]) # Assuming single regression value
|
| 41 |
-
print(prediction)
|
| 42 |
-
confidences = str(prediction)
|
| 43 |
-
return confidences
|
| 44 |
-
|
| 45 |
-
# Create Gradio interface
|
| 46 |
-
input_image = gr.Image()
|
| 47 |
-
output_text = gr.Textbox(label="Predicted Value")
|
| 48 |
-
interface = gr.Interface(fn=predict_pokemons,
|
| 49 |
-
inputs=input_image,
|
| 50 |
-
outputs=gr.Label(),
|
| 51 |
-
description="A simple pokemon classification model based on Xception and Pokemon Images (https://www.kaggle.com/datasets/mikoajkolman/pokemon-images-first-generation17000-files).")
|
| 52 |
-
interface.launch()
|
|
|
|
| 11 |
|
| 12 |
labels = ['Abra', 'Ditto', 'Gengar']
|
| 13 |
|
| 14 |
+
def predict_pokemon_type(uploaded_file):
|
| 15 |
+
if uploaded_file is None:
|
| 16 |
+
return "No file uploaded.", None, "No prediction"
|
| 17 |
+
|
| 18 |
+
# Load the image from the file path
|
| 19 |
+
with Image.open(uploaded_file) as img:
|
| 20 |
+
img = img.resize((150, 150))
|
| 21 |
+
img_array = np.array(img)
|
| 22 |
+
|
| 23 |
+
prediction = model.predict(np.expand_dims(img_array, axis=0))
|
| 24 |
+
|
| 25 |
+
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
| 26 |
+
|
| 27 |
+
return img, confidences
|
| 28 |
+
|
| 29 |
+
# Define the Gradio interface
|
| 30 |
+
iface = gr.Interface(
|
| 31 |
+
fn=predict_pokemon_type,
|
| 32 |
+
inputs=gr.File(label="Upload File"),
|
| 33 |
+
outputs=["image", "text"],
|
| 34 |
+
title="Pokemon Classifier",
|
| 35 |
+
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%!"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Launch the interface
|
| 39 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|