File size: 1,686 Bytes
be177d0
 
 
 
 
 
 
2b934bb
7f26323
2b934bb
 
 
 
82e988a
2b934bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82e988a
2b934bb
 
 
be177d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56364c9
be177d0
 
 
56364c9
 
be177d0
56364c9
be177d0
 
56364c9
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import cv2
import mediapipe as mp
from mediapipe.tasks import python
from mediapipe.tasks.python import vision
import gradio as gr
import os

eng_ara_mapping ={
'':'not clear',
"ain":'ع',
"aleff":'أ',
"bb":'ب',
"dal":'د',
"dha":'ظ',
"dhad":"ض",
"fa":"ف",
"gaaf":'ق',
"ghain":'غ',
"ha":'ه',
"haa":'ح',
"jeem":'ج',
"kaaf":'ك',
"laam":'ل',
"meem":'م',
"nun":"ن",
"ra":'ر',
"saad":'ص',
"seen":'س',
"sheen":"ش",
"ta":'ت',
"taa":'ط',
"thaa":"ث",
"thal":"ذ",
"waw":'و',
"ya" : "ي",
"zay":'ز',
"khaa":'خ' }

def recognize_gesture(image):
    # Load the gesture recognition model
    model_path = os.path.abspath("arabic_signlanguage_characters_model.task")
    recognizer = vision.GestureRecognizer.create_from_model_path(model_path)

    # Convert image to MediaPipe format
    if isinstance(image, gr.Image):  # Check if image is from Gradio
        image = image.to_ndarray(format="bgr")  # Convert to a NumPy array in BGR format

    # Convert image to MediaPipe format
    image = mp.Image(image_format=mp.ImageFormat.SRGB, data=image)

    # Perform gesture recognition
    recognition_result = recognizer.recognize(image)

    # Extract the top gesture
    top_gesture = recognition_result.gestures[0][0]

    # Return the gesture label and score
    return f"Gesture recognized: {eng_ara_mapping[top_gesture.category_name]} ({top_gesture.score:.2f})"

iface = gr.Interface(
    fn=recognize_gesture,
    inputs=["image"],  # Input type: image
    outputs="text",  # Output type: text
    title="Arabic Sign Language Character Recognition",
    description="Upload an image to recognize the gesture",
)

iface.launch()  # Launch the interface in a web browser