Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"),
|
| 59 |
-
outputs=["
|
|
|
|
|
|
|
| 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 |
|