import tensorflow as tf import numpy as np import gradio as gr # With the path to your actual .h5 file model_path = 'model__xception.h5' # Load the pre-trained model model = tf.keras.models.load_model(model_path) ## Define the predict function for Gradio def predict_gradio(image): # Preprocess the input image img_array = tf.image.resize(image, (299, 299)) img_array = tf.keras.preprocessing.image.img_to_array(img_array) img_array = tf.expand_dims(img_array, 0) # Create a batch # Make a prediction using the trained model predictions = model.predict(img_array) print(predictions) score = tf.nn.sigmoid(predictions[0]) return ("This image most likely belongs to {} with a {:.2f} percent confidence.".format(labels[np.argmax(score)], 100 * np.max(score))) #Create a Gradio interface iface = gr.Interface( fn=predict_gradio, inputs=gr.Image(), outputs="label", live=True, cache_examples=False ) # Launch the Gradio interface iface.launch()