import gradio as gr import tensorflow as tf import numpy as np from PIL import Image # Load your custom regression model model_path = "transferlearning_pokemon.keras" #model.load_weights(model_path) model = tf.keras.models.load_model(model_path) labels = ['Abra', 'Ditto', 'Gengar'] def predict_pokemon_type(uploaded_file): if uploaded_file is None: return "No file uploaded.", None, "No prediction" # Load the image from the file path with Image.open(uploaded_file) as img: img = img.resize((150, 150)) img_array = np.array(img) prediction = model.predict(np.expand_dims(img_array, axis=0)) confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))} return img, confidences # Define the Gradio interface iface = gr.Interface( fn=predict_pokemon_type, inputs=gr.File(label="Upload File"), outputs=["image", "text"], title="Pokemon Classifier", description="Upload a picture of a Pokemon (Ditto, Abra or Grengar) to see its type and confidence level." ) # Launch the interface iface.launch()