jleibs commited on
Commit
08fa0b1
1 Parent(s): 5f8336a

Use the published gradio streaming component

Browse files
Files changed (2) hide show
  1. app.py +43 -27
  2. 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 gradio as gr
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
- def html_template(rrd, app_url="https://app.rerun.io"):
56
- encoded_url = urllib.parse.quote(rrd)
57
- return f"""<div style="width:100%; height:70vh;"><iframe style="width:100%; height:100%;" src="{app_url}?url={encoded_url}" frameborder="0" allowfullscreen=""></iframe></div>"""
58
-
59
- def show_cube(x, y, z):
60
- rr.init("my data")
61
 
62
- cube = build_color_grid(int(x), int(y), int(z), twist=0)
63
- rr.log("cube", rr.Points3D(cube.positions, colors=cube.colors, radii=0.5))
 
 
 
64
 
65
- blueprint = rrb.Spatial3DView(origin='cube')
66
 
67
- rr.save("cube.rrd", default_blueprint=blueprint)
68
-
69
- return "cube.rrd"
 
 
 
70
 
71
 
72
  with gr.Blocks() as demo:
73
  with gr.Row():
74
- x_count = gr.Number(minimum=1, maximum=10, value=5, precision=0, label="X Count")
75
- y_count = gr.Number(minimum=1, maximum=10, value=5, precision=0, label="Y Count")
76
- z_count = gr.Number(minimum=1, maximum=10, value=5, precision=0, label="Z Count")
 
 
 
 
 
 
 
 
 
77
  button = gr.Button("Show Cube")
78
- with gr.Row():
79
- rrd = gr.File()
80
- with gr.Row():
81
- viewer = gr.HTML()
82
 
83
- button.click(show_cube, inputs=[x_count, y_count, z_count], outputs=rrd)
84
- rrd.change(html_template, js="""(rrd) => { console.log(rrd.url); return rrd.url}""", inputs=[rrd], outputs=viewer, preprocess=False)
 
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.15.1
 
 
1
+ rerun-sdk==0.16.1
2
+ gradio_rerun==0.0.3