|
|
import gradio as gr |
|
|
import tensorflow as tf |
|
|
import numpy as np |
|
|
from PIL import Image |
|
|
|
|
|
|
|
|
model = tf.keras.models.load_model("my_modal.h5") |
|
|
class_names = ['Class 1', 'Class 2', 'Class 3'] |
|
|
|
|
|
|
|
|
def predict(image): |
|
|
image = image.resize((224, 224)) |
|
|
img_array = np.array(image) / 255.0 |
|
|
img_array = img_array.reshape((1, 224, 224, 3)) |
|
|
prediction = model.predict(img_array) |
|
|
predicted_class = class_names[np.argmax(prediction)] |
|
|
confidence = float(np.max(prediction)) |
|
|
return {predicted_class: confidence} |
|
|
|
|
|
|
|
|
gr.Interface( |
|
|
fn=predict, |
|
|
inputs=gr.Image(type="pil"), |
|
|
outputs=gr.Label(num_top_classes=3), |
|
|
title="My ML Model" |
|
|
).launch() |
|
|
|