taechasith commited on
Commit
5f3e574
·
verified ·
1 Parent(s): 62033c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import cv2
4
+ import mediapipe as mp
5
+ import torch
6
+ import torchaudio
7
+ from scipy.signal import chirp
8
+ import plotly.graph_objects as go
9
+
10
+ # Load MediaPipe Hand Tracking
11
+ mp_hands = mp.solutions.hands
12
+ mp_drawing = mp.solutions.drawing_utils
13
+ hands = mp_hands.Hands(min_detection_confidence=0.7, min_tracking_confidence=0.7)
14
+
15
+ # Generate Quantum Wave Sound
16
+ def generate_wave(frequency=220, duration=3):
17
+ sample_rate = 44100
18
+ t = np.linspace(0, duration, int(sample_rate * duration))
19
+ waveform = chirp(t, f0=frequency, f1=frequency*2, t1=duration, method='quadratic')
20
+ return waveform, sample_rate
21
+
22
+ # 3D Black Hole with Hand Interaction
23
+ def process_frame(frame):
24
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
25
+ results = hands.process(frame_rgb)
26
+
27
+ if results.multi_hand_landmarks:
28
+ for hand_landmarks in results.multi_hand_landmarks:
29
+ mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
30
+ x = hand_landmarks.landmark[mp_hands.HandLandmark.WRIST].x
31
+ y = hand_landmarks.landmark[mp_hands.HandLandmark.WRIST].y
32
+ rotation = (x - 0.5) * 360 # Rotate black hole based on hand position
33
+ return frame, rotation
34
+
35
+ return frame, 0 # Default if no hand detected
36
+
37
+ def black_hole_visualization(rotation):
38
+ fig = go.Figure(go.Surface(z=np.sin(np.linspace(0, 10, 100)[:, None] + np.linspace(0, 10, 100))))
39
+ fig.update_layout(scene_camera=dict(eye=dict(x=1.5*np.cos(np.radians(rotation)), y=1.5*np.sin(np.radians(rotation)), z=1)))
40
+ return fig
41
+
42
+ def run_app(webcam):
43
+ frame, rotation = process_frame(webcam)
44
+ black_hole_figure = black_hole_visualization(rotation)
45
+ wave_data, sr = generate_wave(frequency=200 + rotation)
46
+ return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), black_hole_figure, (wave_data, sr)
47
+
48
+ iface = gr.Interface(fn=run_app,
49
+ inputs=gr.Image(source="webcam", streaming=True),
50
+ outputs=["image", "plot", "audio"],
51
+ live=True)
52
+
53
+ iface.launch()