Spaces:
Runtime error
Runtime error
Commit
·
9f9bcb1
1
Parent(s):
4506fce
final app before bed
Browse files
app.py
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
import os
|
2 |
-
import cv2
|
3 |
-
import numpy as np
|
4 |
-
import gradio as gr
|
5 |
-
import tensorflow as tf
|
6 |
-
import mediapipe as mp
|
7 |
|
|
|
|
|
8 |
|
9 |
N_ROWS = 543
|
10 |
N_DIMS = 3
|
@@ -185,21 +182,34 @@ def extract_keypoints(results):
|
|
185 |
# Make prediction
|
186 |
def make_prediction(processed_landmarks):
|
187 |
inputs = np.array(processed_landmarks, dtype=np.float32)
|
|
|
|
|
188 |
interpreter.set_tensor(input_details[0]['index'], inputs)
|
|
|
|
|
189 |
interpreter.invoke()
|
|
|
|
|
190 |
output_data = interpreter.get_tensor(output_details[0]['index'])
|
|
|
|
|
191 |
index = np.argmax(output_data)
|
192 |
-
|
|
|
|
|
|
|
|
|
193 |
|
194 |
|
195 |
# ...
|
196 |
|
197 |
with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
|
198 |
-
|
|
|
|
|
|
|
199 |
|
200 |
|
201 |
-
# ... (Previous code remains the same)
|
202 |
-
|
203 |
# Modify the predict_with_webcam function to take an image as input and return the prediction string
|
204 |
def predict_with_webcam(frame):
|
205 |
if frame is None:
|
@@ -227,12 +237,6 @@ with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=
|
|
227 |
return "Could not detect landmarks. Make sure your webcam is working properly."
|
228 |
|
229 |
|
230 |
-
# Set mediapipe model
|
231 |
-
cap = cv2.VideoCapture(0)
|
232 |
-
|
233 |
-
cap.release()
|
234 |
-
cv2.destroyAllWindows()
|
235 |
-
|
236 |
# Define the Gradio interface
|
237 |
iface = gr.Interface(
|
238 |
fn=predict_with_webcam, # The function to use for prediction
|
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
import mediapipe as mp
|
4 |
+
import tensorflow as tf
|
5 |
|
6 |
N_ROWS = 543
|
7 |
N_DIMS = 3
|
|
|
182 |
# Make prediction
|
183 |
def make_prediction(processed_landmarks):
|
184 |
inputs = np.array(processed_landmarks, dtype=np.float32)
|
185 |
+
|
186 |
+
# Set the input tensor for the TFLite model
|
187 |
interpreter.set_tensor(input_details[0]['index'], inputs)
|
188 |
+
|
189 |
+
# Invoke the TFLite interpreter to perform inference
|
190 |
interpreter.invoke()
|
191 |
+
|
192 |
+
# Get the output tensor of the TFLite model
|
193 |
output_data = interpreter.get_tensor(output_details[0]['index'])
|
194 |
+
|
195 |
+
# Find the index of the predicted class
|
196 |
index = np.argmax(output_data)
|
197 |
+
|
198 |
+
# Map the index to the corresponding class label using the index_to_class dictionary
|
199 |
+
prediction = inv_index_to_class[index]
|
200 |
+
|
201 |
+
return prediction
|
202 |
|
203 |
|
204 |
# ...
|
205 |
|
206 |
with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
|
207 |
+
import cv2
|
208 |
+
import numpy as np
|
209 |
+
import gradio as gr
|
210 |
+
import tensorflow as tf
|
211 |
|
212 |
|
|
|
|
|
213 |
# Modify the predict_with_webcam function to take an image as input and return the prediction string
|
214 |
def predict_with_webcam(frame):
|
215 |
if frame is None:
|
|
|
237 |
return "Could not detect landmarks. Make sure your webcam is working properly."
|
238 |
|
239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
# Define the Gradio interface
|
241 |
iface = gr.Interface(
|
242 |
fn=predict_with_webcam, # The function to use for prediction
|