Spaces:
Sleeping
Sleeping
File size: 1,165 Bytes
985502b 6b46fb6 985502b e426d59 be8b0b0 985502b e426d59 985502b be8b0b0 985502b 90b23c7 fd5f5e2 be8b0b0 90b23c7 |
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 33 34 35 36 37 38 39 40 |
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()
|