Spaces:
Sleeping
Sleeping
| from pydantic import BaseModel | |
| from typing import List, Optional | |
| class Gesture(BaseModel): | |
| """Represents a detected gesture with metadata.""" | |
| gesture: str | |
| duration: int # Duration in frames | |
| confidence: float | |
| class GestureResponse(BaseModel): | |
| """Response model containing a list of detected gestures.""" | |
| gestures: List[Gesture] | |
| # Primary gesture mappings for the main gestures + additional ones | |
| GESTURE_MAPPING = { | |
| # Original 5 main gestures | |
| 27: "thumbs_up", # like | |
| 31: "palm", # open palm wave (5 fingers) | |
| 32: "peace", # peace sign (2 fingers) | |
| 29: "ok", # OK sign | |
| 20: "call", # call me (little finger) | |
| # Finger counting (1-5) | |
| 30: "one", # 1 finger | |
| 39: "two_up", # 2 fingers (peace sign) | |
| 37: "three", # 3 fingers | |
| 26: "four", # 4 fingers | |
| # Note: 5 fingers is same as palm (31) | |
| # Surprise gesture | |
| 23: "middle_finger", # middle finger (surprise!) | |
| # Additional useful gestures | |
| 25: "fist", # closed fist | |
| 19: "point", # pointing with index finger | |
| 35: "stop", # stop gesture | |
| } | |
| # Production gesture mapping with clean, consistent names | |
| # Hand-agnostic counting (left/right variations map to same gesture) | |
| PRODUCTION_GESTURE_MAPPING = { | |
| # Counting gestures (1-5) - hand agnostic | |
| 30: "one", # 1 finger (any direction) | |
| 42: "one", # 1 finger left (maps to "one") | |
| 43: "one", # 1 finger right (maps to "one") | |
| 44: "one", # 1 finger down (maps to "one") | |
| 32: "two", # 2 fingers (peace sign) | |
| 39: "two", # 2 fingers up (maps to "two") | |
| 14: "two", # 2 fingers left (maps to "two") | |
| 15: "two", # 2 fingers right (maps to "two") | |
| 16: "two", # 2 fingers down (maps to "two") | |
| 37: "three", # 3 fingers (any direction) | |
| 21: "three", # 3 fingers variant (maps to "three") | |
| 38: "three", # 3 fingers variant 2 (maps to "three") | |
| 26: "four", # 4 fingers | |
| 31: "five", # 5 fingers (open palm) | |
| # Extra gestures for production | |
| 27: "thumbs_up", # thumbs up gesture | |
| 23: "middle_finger", # middle finger | |
| 33: "peace_inverted", # peace sign inverted | |
| # Additional useful gestures | |
| 29: "ok", # OK sign | |
| 20: "call", # call me gesture | |
| 25: "fist", # closed fist | |
| 19: "point", # pointing | |
| 35: "stop", # stop gesture | |
| } | |
| # Additional gesture mappings for completeness (all raw model outputs) | |
| FULL_GESTURE_MAPPING = { | |
| 0: "hand_down", | |
| 1: "hand_right", | |
| 2: "hand_left", | |
| 3: "thumb_index", | |
| 4: "thumb_left", | |
| 5: "thumb_right", | |
| 6: "thumb_down", | |
| 7: "half_up", | |
| 8: "half_left", | |
| 9: "half_right", | |
| 10: "half_down", | |
| 11: "part_hand_heart", | |
| 12: "part_hand_heart2", | |
| 13: "fist_inverted", | |
| 14: "two_left", | |
| 15: "two_right", | |
| 16: "two_down", | |
| 17: "grabbing", | |
| 18: "grip", | |
| 19: "point", | |
| 20: "call", | |
| 21: "three3", | |
| 22: "little_finger", | |
| 23: "middle_finger", | |
| 24: "dislike", | |
| 25: "fist", | |
| 26: "four", | |
| 27: "like", | |
| 28: "mute", | |
| 29: "ok", | |
| 30: "one", | |
| 31: "palm", | |
| 32: "peace", | |
| 33: "peace_inverted", | |
| 34: "rock", | |
| 35: "stop", | |
| 36: "stop_inverted", | |
| 37: "three", | |
| 38: "three2", | |
| 39: "two_up", | |
| 40: "two_up_inverted", | |
| 41: "three_gun", | |
| 42: "one_left", | |
| 43: "one_right", | |
| 44: "one_down" | |
| } | |