Spaces:
Sleeping
Sleeping
import gradio as gr | |
import tensorflow as tf | |
from tensorflow import keras | |
from tensorflow.keras.preprocessing.image import img_to_array | |
from tensorflow.image import resize | |
model = keras.models.load_model('memeclf.h5') | |
def predict(image): | |
img = resize(image, (256, 256)) | |
img = img_to_array(img) | |
img = tf.expand_dims(img, axis=0) | |
img = tf.cast(img/255. ,tf.float32) | |
predictions = model.predict(img) | |
if predictions[0] < 0.5: | |
return "Image is a meme" | |
else: | |
return "Image is not a meme" | |
interface = gr.Interface( | |
fn=predict, | |
inputs=gr.Image(), | |
outputs="label", | |
title="Meme Classifier", | |
description="Upload an image and the model will predict if it's a meme or not.", | |
theme="huggingface" | |
) | |
interface.launch() | |