|
import gradio as gr
|
|
import tensorflow as tf
|
|
import numpy as np
|
|
from PIL import Image
|
|
|
|
model_path = "p_inference_fruits/Xeption_fruits.keras"
|
|
model = tf.keras.models.load_model(model_path)
|
|
|
|
|
|
def predict_fruit(image):
|
|
|
|
print(type(image))
|
|
image = Image.fromarray(image.astype('uint8'))
|
|
image = image.resize((150, 150))
|
|
image = np.array(image)
|
|
image = np.expand_dims(image, axis=0)
|
|
|
|
|
|
prediction = model.predict(image)
|
|
|
|
|
|
|
|
prediction = np.round(prediction, 3)
|
|
|
|
|
|
p_apple = prediction[0][0]
|
|
p_banana = prediction[0][1]
|
|
p_pinenapple = prediction[0][2]
|
|
p_strawberries = prediction[0][3]
|
|
p_watermelon = prediction[0][4]
|
|
|
|
return {'apple': p_apple, 'banana': p_banana, 'pinenapple': p_pinenapple, 'strawberries': p_strawberries, 'watermelon': p_watermelon}
|
|
|
|
|
|
input_image = gr.Image()
|
|
iface = gr.Interface(
|
|
fn=predict_fruit,
|
|
inputs=input_image,
|
|
outputs=gr.Label(),
|
|
examples=["p_inference_fruits/images/ap1.jpeg", "p_inference_fruits/images/ap2.jpeg", "p_inference_fruits/images/ap3.jpeg", "p_inference_fruits/images/ba1.jpeg", "p_inference_fruits/images/ba2.jpeg", "p_inference_fruits/images/ba3.jpeg", "p_inference_fruits/images/pi1.jpeg","p_inference_fruits/images/pi2.jpeg","p_inference_fruits/images/pi3.jpeg","p_inference_fruits/images/st1.jpeg", "p_inference_fruits/images/st2.jpeg", "p_inference_fruits/images/st3.jpeg","p_inference_fruits/images/wa1.jpeg","p_inference_fruits/images/wa2.jpeg","p_inference_fruits/images/wa3.jpeg"],
|
|
description="TEST.")
|
|
|
|
iface.launch() |