taechasith commited on
Commit
cf0334c
·
verified ·
1 Parent(s): f84c3c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -21,17 +21,25 @@ def generate_wave(frequency=220, duration=3):
21
 
22
  # Process Hand Tracking
23
  def process_frame(frame):
24
- frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
25
- results = hands.process(frame_rgb)
26
- rotation = 0
 
 
 
 
27
 
28
- if results.multi_hand_landmarks:
29
- for hand_landmarks in results.multi_hand_landmarks:
30
- mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
31
- x = hand_landmarks.landmark[mp_hands.HandLandmark.WRIST].x
32
- rotation = (x - 0.5) * 360 # Rotate black hole based on hand movement
33
 
34
- return frame, rotation # Return frame with hand-tracking + rotation value
 
 
 
 
35
 
36
  # Create Black Hole Visualization
37
  def black_hole_visualization(rotation):
@@ -55,8 +63,10 @@ def run_app(webcam):
55
  # Launch Gradio UI (Fixed Input for New Gradio Versions)
56
  iface = gr.Interface(
57
  fn=run_app,
58
- inputs=gr.Image(type="numpy", label="Webcam Feed"), # ✅ Fixed Input
59
- outputs=["image", "plot", "audio"],
 
 
60
  live=True
61
  )
62
 
 
21
 
22
  # Process Hand Tracking
23
  def process_frame(frame):
24
+ try:
25
+ if frame is None:
26
+ return np.zeros((480, 640, 3), dtype=np.uint8), 0 # Return empty image if no frame
27
+
28
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
29
+ results = hands.process(frame_rgb)
30
+ rotation = 0
31
 
32
+ if results.multi_hand_landmarks:
33
+ for hand_landmarks in results.multi_hand_landmarks:
34
+ mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
35
+ x = hand_landmarks.landmark[mp_hands.HandLandmark.WRIST].x
36
+ rotation = (x - 0.5) * 360 # Rotate black hole based on hand movement
37
 
38
+ return frame, rotation # Return processed frame + rotation angle
39
+
40
+ except Exception as e:
41
+ print(f"Error processing frame: {e}")
42
+ return np.zeros((480, 640, 3), dtype=np.uint8), 0 # Return blank image if error occurs
43
 
44
  # Create Black Hole Visualization
45
  def black_hole_visualization(rotation):
 
63
  # Launch Gradio UI (Fixed Input for New Gradio Versions)
64
  iface = gr.Interface(
65
  fn=run_app,
66
+ inputs=gr.Image(type="numpy", label="Webcam Feed"),
67
+ outputs=[gr.Image(type="numpy", label="Processed Frame"),
68
+ gr.Plot(label="Black Hole Distortion"),
69
+ gr.Audio(label="Quantum Sound Wave")],
70
  live=True
71
  )
72