ankush-003 commited on
Commit
eb20ed3
1 Parent(s): 5a28175

trying threading

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import cv2
2
  import mediapipe as mp
3
  import numpy as np
 
 
4
  mp_drawing = mp.solutions.drawing_utils
5
  mp_pose = mp.solutions.pose
6
  import gradio as gr
@@ -35,13 +37,37 @@ def detect_pose(im):
35
 
36
  return image
37
 
 
 
 
 
 
 
 
38
  with gr.Blocks() as app:
39
  gr.Markdown("# Webcam Testing")
40
  with gr.Row():
41
- inp = gr.Image(source="webcam", streaming=True)
42
  out = gr.Image()
43
-
44
- inp.stream(detect_pose, inputs=inp, outputs=inp, show_progress = "hidden")
45
- out.change(show_progress = "hidden")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  app.launch(debug=True)
 
1
  import cv2
2
  import mediapipe as mp
3
  import numpy as np
4
+ import threading
5
+
6
  mp_drawing = mp.solutions.drawing_utils
7
  mp_pose = mp.solutions.pose
8
  import gradio as gr
 
37
 
38
  return image
39
 
40
+ pose_results = None
41
+
42
+ def update_pose_results(im):
43
+ global pose_results
44
+ pose_results = detect_pose(im)
45
+
46
+
47
  with gr.Blocks() as app:
48
  gr.Markdown("# Webcam Testing")
49
  with gr.Row():
50
+ inp = gr.Image(source="webcam", streaming=True)
51
  out = gr.Image()
52
+
53
+ # Start a separate thread for pose detection
54
+ def pose_detection_thread():
55
+ while True:
56
+ update_pose_results(inp.value)
57
+
58
+ pose_thread = threading.Thread(target=pose_detection_thread)
59
+ pose_thread.daemon = True # Allow the thread to exit when the main program exits
60
+ pose_thread.start()
61
+
62
+ # Continuously update the output with pose results
63
+ def update_output():
64
+ global pose_results
65
+ while True:
66
+ if pose_results is not None:
67
+ out.value = pose_results
68
+
69
+ output_thread = threading.Thread(target=update_output)
70
+ output_thread.daemon = True
71
+ output_thread.start()
72
 
73
  app.launch(debug=True)