import tensorflow as tf from tensorflow.keras.models import load_model import gradio as gr import numpy as np import cv2 import numpy as np import os import sys from tensorflow import keras from tensorflow.keras import layers def get_model(): model = load_model("model_1.h5") model.compile(optimizer="adam", loss="categorical_crossentropy") model.summary() return model model = get_model() labels = ["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thrteen","fourteen","fifteen","sixteen","seventeen","eightteen","nineteen"] def predict(img): img = cv2.resize(img, (64, 64), interpolation=cv2.INTER_AREA) img = img.astype("float32") img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img = img.reshape(1, 64, 64, 1) print(img.shape) out = model.predict(img) print(out.shape) cls = out.argmax() return cls ui = gr.Interface( fn=predict, inputs=gr.Image(type="numpy"), outputs=gr.Textbox() ) ui.launch()