wizzseen's picture
app.py
0d1b4e5 verified
raw
history blame
858 Bytes
import cv2
from tensorflow.keras.models import load_model
import gradio as gr
import tensorflow as tf
import cv2
import numpy as np
from tensorflow.keras.models import load_model
# Load the pre-trained model
new_model = load_model('cat_classifier_model.h5')
def classify_image(image_path):
img = image.load_img(image_path, target_size=(224, 224))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array /= 255.0 # Rescale to values between 0 and 1 (same as during training)
prediction = model.predict(img_array)
if prediction[0][0] > 0.5:
return "not a tablet"
else:
return "is a tablet"
# Create a Gradio interface
iface = gr.Interface(
fn=classify_image,
inputs=gr.Image(),
outputs="text",
live=True,
)
# Launch the Gradio interface
iface.launch()