Spaces:
Sleeping
Sleeping
File size: 919 Bytes
06f5f37 c506c38 06f5f37 d6656e4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import gradio as gr
import tensorflow as tf
import numpy as np
# Load the saved model
model = tf.keras.models.load_model('mymodel.h5')
# Define the labels
labels = ['Buildings', 'Forest', 'Sea']
# Define the image classification function
def classify_image(image):
# Preprocess the image
image = np.array(image)
image = tf.image.resize(image, (128, 128)) # Resize the image to match the input size of the model
image = tf.expand_dims(image, axis=0) # Add batch dimension
image = tf.keras.applications.resnet50.preprocess_input(image)
# Predict the class
predictions = model.predict(image).flatten()
# Get the predicted class label
predicted_class = labels[np.argmax(predictions)]
return predicted_class
# Create the Gradio interface directly
interface = gr.Interface(classify_image, "image", "label", title="Image Classifier")
# Launch the interface
interface.launch()
|