File size: 1,650 Bytes
82f3858 99cc667 28224ec 99cc667 1214d5b 99cc667 90ee468 99cc667 d653516 08af4fa 99cc667 |
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 |
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np
labels = ['barrel_jellyfish','blue_jellyfish','compass_jellyfish','lions_mane_jellyfish','mauve_stinger_jellyfish','Moon_jellyfish']
def predict_jellyfish_type(uploaded_file):
if uploaded_file is None:
return "No file uploaded."
model = tf.keras.models.load_model('Jellyfish_transferlearning.keras')
# Load the image from the file path
with Image.open(uploaded_file) as img:
img = img.resize((150, 150)).convert('RGB') # Convert image to RGB
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 confidences
# Define the Gradio interface
iface = gr.Interface(
fn=predict_jellyfish_type, # Function to process the input
inputs=gr.File(label="Upload File"), # File upload widget
outputs="text", # Output type
title="Jellyfish Classifier", # Title of the interface
examples=["images/barrel_jellyfish.jpeg", "images/blue_jellyfish.jpeg", "images/compass_jellyfish.jpeg", "images/lions_mane_jellyfish.jpeg", "images/mauve_stinger_jellyfish.jpeg", "images/Moon_jellyfish.jpeg"],
description="Upload a picture of a Jellyfish (barrel Gefährlichkeit: Niedrig, blue Gefährlichkeit: Moderat, compass Gefährlichkeit: Moderat, lions mane Gefährlichkeit: Hoch, mauve stinger Gefährlichkeit: Moderat bis Hoch, Moon Gefährlichkeit: Niedrig) " # Description of the interface
)
# Launch the interface
iface.launch() |