|
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') |
|
|
|
with Image.open(uploaded_file) as img: |
|
img = img.resize((150, 150)).convert('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 |
|
|
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_jellyfish_type, |
|
inputs=gr.File(label="Upload File"), |
|
outputs="text", |
|
title="Jellyfish Classifier", |
|
examples=["images/barrel_jellyfish.jpg", "images/blue_jellyfish.jpg", "images/compass_jellyfish.jpg", "images/lions_mane_jellyfish.jpg", "images/mauve_stinger_jellyfish.jpg", "images/Moon_jellyfish.jpg"], |
|
description="Upload a picture of a Jellyfish (preferably barrel, blue, compass, lions mane, mauve stinger, Moon)" |
|
) |
|
|
|
|
|
iface.launch() |