File size: 757 Bytes
3618817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()