Spaces:
Sleeping
Sleeping
Use the published gradio streaming component
Browse files- app.py +43 -27
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,13 +1,18 @@
|
|
1 |
-
import rerun as rr
|
2 |
-
import rerun.blueprint as rrb
|
3 |
import numpy as np
|
4 |
-
import
|
5 |
-
import urllib
|
6 |
-
from math import cos, sin
|
7 |
from collections import namedtuple
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
ColorGrid = namedtuple("ColorGrid", ["positions", "colors"])
|
10 |
|
|
|
11 |
def build_color_grid(x_count=10, y_count=10, z_count=10, twist=0):
|
12 |
"""
|
13 |
Create a cube of points with colors.
|
@@ -52,36 +57,47 @@ def build_color_grid(x_count=10, y_count=10, z_count=10, twist=0):
|
|
52 |
return ColorGrid(positions.T, colors.T.astype(np.uint8))
|
53 |
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
def show_cube(x, y, z):
|
60 |
-
rr.init("my data")
|
61 |
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
70 |
|
71 |
|
72 |
with gr.Blocks() as demo:
|
73 |
with gr.Row():
|
74 |
-
x_count = gr.Number(
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
button = gr.Button("Show Cube")
|
78 |
-
with gr.Row():
|
79 |
-
|
80 |
-
with gr.Row():
|
81 |
-
viewer = gr.HTML()
|
82 |
|
83 |
-
button.click(
|
84 |
-
|
|
|
85 |
|
86 |
-
|
87 |
demo.launch()
|
|
|
|
|
|
|
1 |
import numpy as np
|
2 |
+
from math import cos, sin, pi
|
|
|
|
|
3 |
from collections import namedtuple
|
4 |
+
import time
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
from gradio_rerun import Rerun
|
8 |
+
|
9 |
+
import rerun as rr
|
10 |
+
import rerun.blueprint as rrb
|
11 |
+
|
12 |
|
13 |
ColorGrid = namedtuple("ColorGrid", ["positions", "colors"])
|
14 |
|
15 |
+
|
16 |
def build_color_grid(x_count=10, y_count=10, z_count=10, twist=0):
|
17 |
"""
|
18 |
Create a cube of points with colors.
|
|
|
57 |
return ColorGrid(positions.T, colors.T.astype(np.uint8))
|
58 |
|
59 |
|
60 |
+
@rr.thread_local_stream("rerun_example_cube")
|
61 |
+
def show_cube(x, y, z, twist):
|
62 |
+
stream = rr.binary_stream()
|
|
|
|
|
|
|
63 |
|
64 |
+
blueprint = rrb.Blueprint(
|
65 |
+
rrb.Spatial3DView(origin="cube"),
|
66 |
+
collapse_panels=True,
|
67 |
+
)
|
68 |
+
rr.send_blueprint(blueprint)
|
69 |
|
70 |
+
yield stream.read()
|
71 |
|
72 |
+
for step in range(twist):
|
73 |
+
rr.set_time_sequence("steps", step)
|
74 |
+
cube = build_color_grid(int(x), int(y), int(z), twist=pi * step / 180)
|
75 |
+
rr.log("cube", rr.Points3D(cube.positions, colors=cube.colors, radii=0.5))
|
76 |
+
yield stream.read()
|
77 |
+
time.sleep(0.01)
|
78 |
|
79 |
|
80 |
with gr.Blocks() as demo:
|
81 |
with gr.Row():
|
82 |
+
x_count = gr.Number(
|
83 |
+
minimum=1, maximum=20, value=10, precision=0, label="X Count"
|
84 |
+
)
|
85 |
+
y_count = gr.Number(
|
86 |
+
minimum=1, maximum=20, value=10, precision=0, label="Y Count"
|
87 |
+
)
|
88 |
+
z_count = gr.Number(
|
89 |
+
minimum=1, maximum=20, value=10, precision=0, label="Z Count"
|
90 |
+
)
|
91 |
+
twist_steps = gr.Number(
|
92 |
+
minimum=0, maximum=180, value=90, precision=0, label="Twist (degrees)"
|
93 |
+
)
|
94 |
button = gr.Button("Show Cube")
|
95 |
+
with gr.Row():
|
96 |
+
viewer = Rerun(streaming=True)
|
|
|
|
|
97 |
|
98 |
+
button.click(
|
99 |
+
show_cube, inputs=[x_count, y_count, z_count, twist_steps], outputs=viewer
|
100 |
+
)
|
101 |
|
102 |
+
demo.queue(default_concurrency_limit=10)
|
103 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
rerun-sdk==0.
|
|
|
|
1 |
+
rerun-sdk==0.16.1
|
2 |
+
gradio_rerun==0.0.3
|