import numpy as np import tensorflow as tf import gradio as gr from tensorflow.keras.optimizers import Adam from huggingface_hub import from_pretrained_keras reloaded_model = from_pretrained_keras('ShaharAdar/best-model-try') reloaded_model.compile(optimizer=Adam(0.00001), loss='categorical_crossentropy', metrics=['accuracy'] ) 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 = reloaded_model.predict(image) # Assuming the output is a softmax layer, get the predicted class index predicted_class = tf.argmax(preds, axis=1).numpy()[0] # Optionally, convert class index to label if you have a mapping 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'] # example labels 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()