|
import gradio as gr |
|
import tensorflow as tf |
|
from PIL import Image |
|
import numpy as np |
|
|
|
labels = ['Banana', 'Coconut', 'Eggplant', 'Mango', 'Melon', 'Orange', 'Pineapple', 'Watermelon'] |
|
|
|
def predict_pokemon_type(uploaded_file): |
|
if uploaded_file is None: |
|
return "No file uploaded.", None, "No prediction" |
|
|
|
model = tf.keras.models.load_model('fruits-xception-model.keras') |
|
|
|
|
|
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 |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_pokemon_type, |
|
inputs=gr.File(label="Upload File"), |
|
outputs=["image", "text"], |
|
title="Fruit Classifier", |
|
description="Upload a picture of a Fruit (preferably a Banana, Coconut, Eggplant, Mango, Melon, Orange, Pineapple or Watermelon) to see what fruit it is and the models confidence level. Accuracy: 0.8997 - Loss: 0.4229 on Test Data" |
|
) |
|
|
|
|
|
iface.launch() |
|
|