import os os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # Disable GPU usage import gradio as gr import tensorflow as tf from tensorflow.keras.preprocessing import image import numpy as np # Load your trained Xception model model = tf.keras.models.load_model("https://huggingface.co/icputrd/gelderman_decomposition_classification/blob/main/head/xception_070523") def classify_image(img): # Preprocess the image img = img.resize((299, 299)) # Resize to the input shape of Xception img_array = image.img_to_array(img) # Convert image to array img_array = np.expand_dims(img_array, axis=0) # Add batch dimension img_array /= 255.0 # Normalize the image # Make prediction predictions = model.predict(img_array) predicted_class = np.argmax(predictions, axis=-1)[0] # Get the predicted class index return str(predicted_class) # Return the class index as a string # Set up Gradio interface iface = gr.Interface(fn=classify_image, inputs=gr.inputs.Image(type="pil"), outputs="text") iface.launch()