Update app.py
Browse files
app.py
CHANGED
@@ -2,56 +2,42 @@ import random
|
|
2 |
import time
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
from fastrtc import WebRTC
|
7 |
|
8 |
def video_generation_handler(prompt):
|
9 |
-
|
10 |
-
seed = random.randint(0, 2**32 - 1)
|
11 |
-
|
12 |
-
random.seed(seed)
|
13 |
-
np.random.seed(seed)
|
14 |
-
|
15 |
-
time.sleep(0.5)
|
16 |
-
|
17 |
-
num_frames = 60
|
18 |
width, height = 832, 480
|
19 |
|
20 |
for frame_idx in range(num_frames):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
value = 0.8 + 0.2 * np.sin(frame_idx * 0.2) # Vary brightness
|
25 |
|
26 |
-
# Convert HSV to RGB
|
27 |
-
import colorsys
|
28 |
r, g, b = colorsys.hsv_to_rgb(hue/360, saturation, value)
|
29 |
|
30 |
-
|
31 |
-
frame_np = np.full((height, width, 3), [r*255, g*255, b*255], dtype=np.uint8)
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
frame_np = np.clip(frame_np.astype(np.int16) + noise, 0, 255).astype(np.uint8)
|
36 |
|
37 |
-
# Add some simple animation (moving gradient)
|
38 |
x_grad = np.linspace(0, 1, width)
|
39 |
y_grad = np.linspace(0, 1, height)
|
40 |
X, Y = np.meshgrid(x_grad, y_grad)
|
41 |
|
42 |
-
# Moving wave pattern
|
43 |
wave = np.sin(X * 4 + frame_idx * 0.2) * np.sin(Y * 4 + frame_idx * 0.3)
|
44 |
-
wave_normalized = ((wave + 1) / 2 *
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
frame_np[:, :, (frame_idx // 10) % 3].astype(np.int16) + wave_normalized,
|
49 |
0, 255
|
50 |
).astype(np.uint8)
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
|
|
55 |
|
56 |
print("🎉 Dummy stream finished!")
|
57 |
|
@@ -66,7 +52,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Dummy FastRTC Demo") as demo:
|
|
66 |
with gr.Group():
|
67 |
prompt = gr.Textbox(
|
68 |
label="Prompt",
|
69 |
-
placeholder="Enter any prompt
|
70 |
lines=3,
|
71 |
value="A colorful animated demo"
|
72 |
)
|
@@ -75,7 +61,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Dummy FastRTC Demo") as demo:
|
|
75 |
|
76 |
with gr.Column(scale=3):
|
77 |
gr.Markdown("### 2. View Live Stream")
|
78 |
-
gr.Markdown("Click 'Start Generation'
|
79 |
|
80 |
webrtc_output = WebRTC(
|
81 |
label="Video Stream",
|
|
|
2 |
import time
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
5 |
+
import colorsys
|
6 |
|
7 |
from fastrtc import WebRTC
|
8 |
|
9 |
def video_generation_handler(prompt):
|
10 |
+
num_frames = 120
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
width, height = 832, 480
|
12 |
|
13 |
for frame_idx in range(num_frames):
|
14 |
+
hue = (frame_idx * 3) % 360
|
15 |
+
saturation = 0.7 + 0.3 * np.sin(frame_idx * 0.1)
|
16 |
+
value = 0.8 + 0.2 * np.sin(frame_idx * 0.2)
|
|
|
17 |
|
|
|
|
|
18 |
r, g, b = colorsys.hsv_to_rgb(hue/360, saturation, value)
|
19 |
|
20 |
+
rgb_frame = np.full((height, width, 3), [r*255, g*255, b*255], dtype=np.uint8)
|
|
|
21 |
|
22 |
+
noise = np.random.randint(-15, 15, (height, width, 3), dtype=np.int16)
|
23 |
+
rgb_frame = np.clip(rgb_frame.astype(np.int16) + noise, 0, 255).astype(np.uint8)
|
|
|
24 |
|
|
|
25 |
x_grad = np.linspace(0, 1, width)
|
26 |
y_grad = np.linspace(0, 1, height)
|
27 |
X, Y = np.meshgrid(x_grad, y_grad)
|
28 |
|
|
|
29 |
wave = np.sin(X * 4 + frame_idx * 0.2) * np.sin(Y * 4 + frame_idx * 0.3)
|
30 |
+
wave_normalized = ((wave + 1) / 2 * 40).astype(np.uint8)
|
31 |
|
32 |
+
rgb_frame[:, :, (frame_idx // 20) % 3] = np.clip(
|
33 |
+
rgb_frame[:, :, (frame_idx // 20) % 3].astype(np.int16) + wave_normalized,
|
|
|
34 |
0, 255
|
35 |
).astype(np.uint8)
|
36 |
|
37 |
+
bgr_frame = rgb_frame[:, :, ::-1]
|
38 |
|
39 |
+
yield bgr_frame
|
40 |
+
time.sleep(0.033) # 30 fps
|
41 |
|
42 |
print("🎉 Dummy stream finished!")
|
43 |
|
|
|
52 |
with gr.Group():
|
53 |
prompt = gr.Textbox(
|
54 |
label="Prompt",
|
55 |
+
placeholder="Enter any prompt to change the random seed",
|
56 |
lines=3,
|
57 |
value="A colorful animated demo"
|
58 |
)
|
|
|
61 |
|
62 |
with gr.Column(scale=3):
|
63 |
gr.Markdown("### 2. View Live Stream")
|
64 |
+
gr.Markdown("Click 'Start Generation' to begin streaming frames.")
|
65 |
|
66 |
webrtc_output = WebRTC(
|
67 |
label="Video Stream",
|