Spaces:
Runtime error
Runtime error
JefferyJapheth
commited on
Commit
•
3d1072b
1
Parent(s):
7244605
Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,7 @@ index_to_class = {
|
|
31 |
|
32 |
inv_index_to_class = {v: k for k, v in index_to_class.items()}
|
33 |
|
34 |
-
|
35 |
|
36 |
# Preprocess landmarks
|
37 |
def preprocess_landmarks(hand1_landmarks, hand2_landmarks, pose_landmarks, lip_landmarks):
|
@@ -72,15 +72,43 @@ def extract_landmarks(frame):
|
|
72 |
|
73 |
# Make prediction
|
74 |
def make_prediction(processed_landmarks):
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
return print(processed_landmarks) #index_to_class[index]
|
81 |
|
82 |
# Gradio Interface Function
|
83 |
def predict_with_webcam(frame):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
landmarks = extract_landmarks(frame)
|
85 |
if landmarks is not None:
|
86 |
processed_landmarks = preprocess_landmarks(*landmarks)
|
|
|
31 |
|
32 |
inv_index_to_class = {v: k for k, v in index_to_class.items()}
|
33 |
|
34 |
+
webcam = cv2.VideoCapture(0)
|
35 |
|
36 |
# Preprocess landmarks
|
37 |
def preprocess_landmarks(hand1_landmarks, hand2_landmarks, pose_landmarks, lip_landmarks):
|
|
|
72 |
|
73 |
# Make prediction
|
74 |
def make_prediction(processed_landmarks):
|
75 |
+
inputs = np.array([processed_landmarks])
|
76 |
+
interpreter.set_tensor(input_details[0]['index'], inputs)
|
77 |
+
interpreter.invoke()
|
78 |
+
index = outputs[0].argmax()
|
79 |
+
return index_to_class[index]
|
|
|
80 |
|
81 |
# Gradio Interface Function
|
82 |
def predict_with_webcam(frame):
|
83 |
+
|
84 |
+
# Initialize webcam capture (the default camera, usually index 0)
|
85 |
+
webcam = cv2.VideoCapture(0)
|
86 |
+
|
87 |
+
while True:
|
88 |
+
# Capture a frame from the webcam
|
89 |
+
ret, frame = webcam.read()
|
90 |
+
|
91 |
+
if not ret:
|
92 |
+
print("Failed to capture frame from the webcam.")
|
93 |
+
break
|
94 |
+
|
95 |
+
landmarks = extract_landmarks(frame)
|
96 |
+
if landmarks is not None:
|
97 |
+
processed_landmarks = preprocess_landmarks(*landmarks)
|
98 |
+
prediction = make_prediction(processed_landmarks)
|
99 |
+
print("Prediction:", prediction)
|
100 |
+
|
101 |
+
# Display the frame in a window (optional)
|
102 |
+
cv2.imshow("Webcam", frame)
|
103 |
+
|
104 |
+
# Break the loop when the user presses the 'q' key
|
105 |
+
if cv2.waitKey(1) & 0xFF == ord('q'):
|
106 |
+
break
|
107 |
+
|
108 |
+
# Release the webcam and close the window
|
109 |
+
webcam.release()
|
110 |
+
cv2.destroyAllWindows()
|
111 |
+
|
112 |
landmarks = extract_landmarks(frame)
|
113 |
if landmarks is not None:
|
114 |
processed_landmarks = preprocess_landmarks(*landmarks)
|