prakasa1234 commited on
Commit
cb2cf6f
·
1 Parent(s): 8644732

First draft

Browse files
Files changed (4) hide show
  1. README.md +7 -12
  2. app.py +89 -0
  3. requirements.txt +0 -0
  4. yolov11n_finetuned_ASL.pt +3 -0
README.md CHANGED
@@ -1,13 +1,8 @@
1
- ---
2
- title: ASL Classifier
3
- emoji: 📊
4
- colorFrom: gray
5
- colorTo: blue
6
- sdk: gradio
7
- sdk_version: 5.49.1
8
- app_file: app.py
9
- pinned: false
10
- short_description: ASL Classifier App
11
- ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
1
+ # 🖐️ ASL Letter Classifier (YOLOv11 + MediaPipe)
 
 
 
 
 
 
 
 
 
 
2
 
3
+ This app uses:
4
+ - **YOLOv11 Classification** (fine-tuned on ASL alphabet images)
5
+ - **MediaPipe Hand Landmarks** for hand annotation
6
+ - **Gradio Web UI** for uploading and testing images
7
+
8
+ Upload a photo of a hand sign to see the detected letter and confidence.
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ultralytics import YOLO
2
+ import gradio as gr
3
+ import cv2
4
+ import os
5
+ import numpy as np
6
+ from mediapipe import Image
7
+ from mediapipe.tasks import python
8
+ from mediapipe.tasks.python import vision
9
+
10
+ # ---------------------
11
+ # Load YOLO model
12
+ # ---------------------
13
+ MODEL_PATH = "yolov11n_finetuned_ASL.pt"
14
+ HAND_MODEL_PATH = "hand_landmarker.task"
15
+ OUTPUT_DIR = "annotated_uploads"
16
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
17
+
18
+ model = YOLO(MODEL_PATH)
19
+
20
+ # ---------------------
21
+ # Load MediaPipe hand landmark detector
22
+ # ---------------------
23
+ base_options = python.BaseOptions(model_asset_path=HAND_MODEL_PATH)
24
+ options = vision.HandLandmarkerOptions(base_options=base_options, num_hands=1)
25
+ detector = vision.HandLandmarker.create_from_options(options)
26
+
27
+ # ---------------------
28
+ # Helper: Annotate image with landmarks
29
+ # ---------------------
30
+ def annotate_with_mediapipe(image_path):
31
+ img = cv2.imread(image_path)
32
+ if img is None:
33
+ return image_path # fallback
34
+
35
+ mp_image = Image.create_from_file(image_path)
36
+ detection_result = detector.detect(mp_image)
37
+
38
+ if detection_result.hand_landmarks:
39
+ for hand_landmarks in detection_result.hand_landmarks:
40
+ for landmark in hand_landmarks:
41
+ h, w, _ = img.shape
42
+ x, y = int(landmark.x * w), int(landmark.y * h)
43
+ cv2.circle(img, (x, y), 3, (0, 255, 0), -1) # green points
44
+
45
+ annotated_path = os.path.join(OUTPUT_DIR, os.path.basename(image_path))
46
+ cv2.imwrite(annotated_path, img)
47
+ return annotated_path
48
+
49
+ # ---------------------
50
+ # Prediction function
51
+ # ---------------------
52
+ def predict(image):
53
+ # Save uploaded image temporarily
54
+ temp_path = "temp_upload.jpg"
55
+ image.save(temp_path)
56
+
57
+ # Step 1: Annotate
58
+ annotated_path = annotate_with_mediapipe(temp_path)
59
+
60
+ # Step 2: Run YOLO prediction
61
+ results = model.predict(annotated_path, imgsz=300, verbose=False)[0]
62
+ probs = results.probs
63
+ top_idx = probs.top1
64
+ top_label = results.names[top_idx]
65
+ confidence = probs.data[top_idx].item()
66
+
67
+ # Step 3: Load annotated image for display
68
+ annotated_img = cv2.imread(annotated_path)
69
+ annotated_img = cv2.cvtColor(annotated_img, cv2.COLOR_BGR2RGB)
70
+
71
+ return annotated_img, {top_label: confidence}
72
+
73
+ # ---------------------
74
+ # Build Gradio Interface
75
+ # ---------------------
76
+ demo = gr.Interface(
77
+ fn=predict,
78
+ inputs=gr.Image(type="pil", label="Upload a Hand Image"),
79
+ outputs=[
80
+ gr.Image(label="Annotated Image"),
81
+ gr.Label(label="Predicted Letter (Confidence)")
82
+ ],
83
+ title="🖐️ ASL Letter Classifier",
84
+ description="Upload an image of a hand gesture. The app will detect landmarks using MediaPipe and classify the ASL letter using YOLOv11.",
85
+ allow_flagging="never"
86
+ )
87
+
88
+ if __name__ == "__main__":
89
+ demo.launch()
requirements.txt ADDED
File without changes
yolov11n_finetuned_ASL.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f5f1e19e26f3024d8b7ba2df598bf6981728cdc6ebd133975a85af08e5682c2
3
+ size 3246722