Update app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,13 @@ import tensorflow as tf
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
labels = ['
|
| 7 |
|
| 8 |
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('
|
| 13 |
|
| 14 |
# Load the image from the file path
|
| 15 |
with Image.open(uploaded_file) as img:
|
|
@@ -18,17 +18,18 @@ def predict_pokemon_type(uploaded_file):
|
|
| 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="
|
| 31 |
-
description="Upload a picture of a
|
| 32 |
)
|
| 33 |
|
| 34 |
# Launch the interface
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
labels = ['Banana', 'Coconut', 'Eggplant', 'Mango', 'Melon', 'Orange', 'Pineapple', 'Watermelon']
|
| 7 |
|
| 8 |
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('fruits-xception-model.keras')
|
| 13 |
|
| 14 |
# Load the image from the file path
|
| 15 |
with Image.open(uploaded_file) as img:
|
|
|
|
| 18 |
|
| 19 |
prediction = model.predict(np.expand_dims(img_array, axis=0))
|
| 20 |
|
| 21 |
+
# Identify the most confident prediction
|
| 22 |
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
| 23 |
|
| 24 |
return img, confidences
|
| 25 |
|
| 26 |
# Define the Gradio interface
|
| 27 |
iface = gr.Interface(
|
| 28 |
+
fn=predict_pokemon_type, # Function to process the input
|
| 29 |
+
inputs=gr.File(label="Upload File"), # File upload widget
|
| 30 |
+
outputs=["image", "text"], # Output types for image and text
|
| 31 |
+
title="Fruit Classifier", # Title of the interface
|
| 32 |
+
description="Upload a picture of a Fruit (preferably a Banana, Coconut, Eggplant, Mango, Melon, Orange, Pineapple or Watermelon) to see what fruit it is and the models confidence level. Accuracy: 0.8997 - Loss: 0.4229 on Test Data" # Description of the interface
|
| 33 |
)
|
| 34 |
|
| 35 |
# Launch the interface
|