prakasa1234 commited on
Commit
0ecb150
·
1 Parent(s): 974f291

changed task

Browse files
Files changed (2) hide show
  1. app.py +20 -0
  2. requirements.txt +5 -0
app.py CHANGED
@@ -6,6 +6,14 @@ 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
@@ -46,6 +54,17 @@ def annotate_with_mediapipe(image_path):
46
  cv2.imwrite(annotated_path, img)
47
  return annotated_path
48
 
 
 
 
 
 
 
 
 
 
 
 
49
  # ---------------------
50
  # Prediction function
51
  # ---------------------
@@ -86,4 +105,5 @@ demo = gr.Interface(
86
  )
87
 
88
  if __name__ == "__main__":
 
89
  demo.launch()
 
6
  from mediapipe import Image
7
  from mediapipe.tasks import python
8
  from mediapipe.tasks.python import vision
9
+ import os
10
+ import requests
11
+
12
+ # Path to save the model locally inside the Space
13
+ HAND_MODEL_PATH = "hand_landmarker.task"
14
+
15
+ # URL to download from (official MediaPipe mirror)
16
+ HAND_MODEL_URL = "https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task"
17
 
18
  # ---------------------
19
  # Load YOLO model
 
54
  cv2.imwrite(annotated_path, img)
55
  return annotated_path
56
 
57
+ def ensure_hand_model():
58
+ """Download the MediaPipe hand landmark model if not already present."""
59
+ if not os.path.exists(HAND_MODEL_PATH):
60
+ print("📥 Downloading MediaPipe hand landmark model...")
61
+ r = requests.get(HAND_MODEL_URL)
62
+ with open(HAND_MODEL_PATH, "wb") as f:
63
+ f.write(r.content)
64
+ print("✅ Download complete.")
65
+ else:
66
+ print("✅ MediaPipe hand landmark model already exists.")
67
+
68
  # ---------------------
69
  # Prediction function
70
  # ---------------------
 
105
  )
106
 
107
  if __name__ == "__main__":
108
+ ensure_hand_model()
109
  demo.launch()
requirements.txt CHANGED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ ultralytics
2
+ torch
3
+ gradio
4
+ mediapipe
5
+ requests