ShaharAdar's picture
Update app.py
bcc19f8 verified
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import BatchNormalization
model = tf.keras.models.load_model('best_model.h5')
labels = ['Clams', 'Corals', 'Crabs', 'Dolphin', 'Eel', 'Fish',
'Jelly Fish', 'Lobster', 'Nudibranchs', 'Octopus', 'Otter',
'Penguin', 'Puffers', 'Sea Rays', 'Sea Urchins', 'Seahorse',
'Seal', 'Sharks', 'Shrimp', 'Squid', 'Starfish',
'Turtle_Tortoise', 'Whale']
def classify_image(image):
# Resize the image to 224x224 as expected by your model
image = tf.image.resize(image, (224, 224))
# Add a batch dimension and make prediction
image = tf.expand_dims(image, 0) # model expects a batch of images
preds = model.predict(image)
# Assuming the output is a softmax layer, get the predicted class index
predicted_class = tf.argmax(preds, axis=1).numpy()[0]
return labels[predicted_class]
import gradio as gr
# Define the interface
iface = gr.Interface(fn=classify_image, inputs="image", outputs="text")
# Launch the application
iface.launch()