File size: 1,121 Bytes
5db7732
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
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.HTML(label="")
output = gr.outputs.Label(num_top_classes=5)
# output = "text"
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()