import gradio as gr import tensorflow as tf import numpy as np from PIL import Image # Load your custom regression model model_path = "transferlearning_fruits.keras" #model.load_weights(model_path) model = tf.keras.models.load_model(model_path) labels = ['freshapples', 'freshbanana', 'freshtomato','rottenapples', 'rottenbanana', 'rottentomato' ] 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", gr.Label(num_top_classes=6)], title="Fruit Classifier", description="Upload a picture of an apple, banana or a tomato." ) # Launch the interface iface.launch()