File size: 465 Bytes
8b56f43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

# Load model
model = tf.keras.models.load_model("model.h5")

# Prediction function
def predict(image):
    image = image.resize((48,48))   # change size if needed
    image = np.array(image)/255.0
    image = np.expand_dims(image, axis=0)
    
    pred = model.predict(image)
    return str(np.argmax(pred))

# UI
gr.Interface(fn=predict, inputs="image", outputs="text").launch()