|
import cv2 |
|
from tensorflow.keras.models import load_model |
|
import matplotlib.pyplot as plt |
|
import numpy as np |
|
from PIL import Image |
|
import gradio as gr |
|
|
|
def recog(img): |
|
model = load_model('hack36_2.h5') |
|
|
|
img_array = np.asarray(img) |
|
clone = img_array.copy() |
|
clone_resized = cv2.resize(clone, (64,64)) |
|
img_array=clone_resized/255 |
|
img_final = np.expand_dims(img_array, axis=0) |
|
prediction = model.predict(img_final).tolist()[0] |
|
alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'space', 'space', 'space'] |
|
|
|
return {alphabet[i]: prediction[i] for i in range(29)} |
|
|
|
|
|
title = "ASL Fingerspelling Recognition" |
|
desc = "" |
|
input = gr.inputs.Image(type="pil", source="webcam") |
|
|
|
output = gr.outputs.Label(num_top_classes=5) |
|
|
|
examples = [ |
|
["B_test.jpg"], |
|
["C_test.jpg"], |
|
["Y_test.jpg"] |
|
] |
|
|
|
iface = gr.Interface( |
|
fn=recog, |
|
title=title, |
|
description=desc, |
|
examples=examples, |
|
inputs=input, |
|
outputs=output |
|
) |
|
|
|
iface.launch() |