Skip to content

Commit 357306d

Browse files
committedJul 9, 2024
update readme + demo
1 parent c7f6f6e commit 357306d

File tree

3 files changed

+116
-57
lines changed

3 files changed

+116
-57
lines changed
 

‎README.md

+47-17
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ with gr.Blocks() as demo:
122122
img = gr.Image(interactive=True, label="Image")
123123
with gr.Column():
124124
stream_blur = gr.Button("Stream Repeated Blur")
125+
with gr.Row():
126+
viewer = Rerun(
127+
streaming=True,
128+
panel_states={
129+
"time": "collapsed",
130+
"blueprint": "hidden",
131+
"selection": "hidden",
132+
},
133+
)
134+
stream_blur.click(streaming_repeated_blur, inputs=[img], outputs=[viewer])
125135

126136
with gr.Tab("Dynamic RRD"):
127137
pending_cleanup = gr.State(
@@ -139,6 +149,20 @@ with gr.Blocks() as demo:
139149
)
140150
with gr.Row():
141151
create_rrd = gr.Button("Create RRD")
152+
with gr.Row():
153+
viewer = Rerun(
154+
streaming=True,
155+
panel_states={
156+
"time": "collapsed",
157+
"blueprint": "hidden",
158+
"selection": "hidden",
159+
},
160+
)
161+
create_rrd.click(
162+
create_cube_rrd,
163+
inputs=[x_count, y_count, z_count, pending_cleanup],
164+
outputs=[viewer],
165+
)
142166

143167
with gr.Tab("Hosted RRD"):
144168
with gr.Row():
@@ -152,23 +176,16 @@ with gr.Blocks() as demo:
152176
f"{rr.bindings.get_app_url()}/examples/plots.rrd",
153177
],
154178
)
155-
156-
# Rerun 0.16 has issues when embedded in a Gradio tab, so we share a viewer between all the tabs.
157-
# In 0.17 we can instead scope each viewer to its own tab to clean up these examples further.
158-
with gr.Row():
159-
viewer = Rerun(
160-
streaming=True,
161-
)
162-
163-
stream_blur.click(streaming_repeated_blur, inputs=[img], outputs=[viewer])
164-
165-
create_rrd.click(
166-
create_cube_rrd,
167-
inputs=[x_count, y_count, z_count, pending_cleanup],
168-
outputs=[viewer],
169-
)
170-
171-
choose_rrd.change(lambda x: x, inputs=[choose_rrd], outputs=[viewer])
179+
with gr.Row():
180+
viewer = Rerun(
181+
streaming=True,
182+
panel_states={
183+
"time": "collapsed",
184+
"blueprint": "hidden",
185+
"selection": "hidden",
186+
},
187+
)
188+
choose_rrd.change(lambda x: x, inputs=[choose_rrd], outputs=[viewer])
172189

173190

174191
if __name__ == "__main__":
@@ -363,6 +380,19 @@ bool
363380
<td align="left"><code>True</code></td>
364381
<td align="left">If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.</td>
365382
</tr>
383+
384+
<tr>
385+
<td align="left"><code>panel_states</code></td>
386+
<td align="left" style="width: 25%;">
387+
388+
```python
389+
dict[str, Any] | None
390+
```
391+
392+
</td>
393+
<td align="left"><code>None</code></td>
394+
<td align="left">Force viewer panels to a specific state. Any panels set cannot be toggled by the user in the viewer. Panel names are "top", "blueprint", "selection", and "time". States are "hidden", "collapsed", and "expanded".</td>
395+
</tr>
366396
</tbody></table>
367397

368398

‎demo/app.py

+34-22
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ def cleanup_cube_rrds(pending_cleanup):
9797
img = gr.Image(interactive=True, label="Image")
9898
with gr.Column():
9999
stream_blur = gr.Button("Stream Repeated Blur")
100+
with gr.Row():
101+
viewer = Rerun(
102+
streaming=True,
103+
panel_states={
104+
"time": "collapsed",
105+
"blueprint": "hidden",
106+
"selection": "hidden",
107+
},
108+
)
109+
stream_blur.click(streaming_repeated_blur, inputs=[img], outputs=[viewer])
100110

101111
with gr.Tab("Dynamic RRD"):
102112
pending_cleanup = gr.State(
@@ -114,6 +124,20 @@ def cleanup_cube_rrds(pending_cleanup):
114124
)
115125
with gr.Row():
116126
create_rrd = gr.Button("Create RRD")
127+
with gr.Row():
128+
viewer = Rerun(
129+
streaming=True,
130+
panel_states={
131+
"time": "collapsed",
132+
"blueprint": "hidden",
133+
"selection": "hidden",
134+
},
135+
)
136+
create_rrd.click(
137+
create_cube_rrd,
138+
inputs=[x_count, y_count, z_count, pending_cleanup],
139+
outputs=[viewer],
140+
)
117141

118142
with gr.Tab("Hosted RRD"):
119143
with gr.Row():
@@ -127,28 +151,16 @@ def cleanup_cube_rrds(pending_cleanup):
127151
f"{rr.bindings.get_app_url()}/examples/plots.rrd",
128152
],
129153
)
130-
131-
# Rerun 0.16 has issues when embedded in a Gradio tab, so we share a viewer between all the tabs.
132-
# In 0.17 we can instead scope each viewer to its own tab to clean up these examples further.
133-
with gr.Row():
134-
viewer = Rerun(
135-
streaming=True,
136-
panel_states={
137-
"time": "hidden",
138-
"blueprint": "hidden",
139-
"selection": "hidden",
140-
},
141-
)
142-
143-
stream_blur.click(streaming_repeated_blur, inputs=[img], outputs=[viewer])
144-
145-
create_rrd.click(
146-
create_cube_rrd,
147-
inputs=[x_count, y_count, z_count, pending_cleanup],
148-
outputs=[viewer],
149-
)
150-
151-
choose_rrd.change(lambda x: x, inputs=[choose_rrd], outputs=[viewer])
154+
with gr.Row():
155+
viewer = Rerun(
156+
streaming=True,
157+
panel_states={
158+
"time": "collapsed",
159+
"blueprint": "hidden",
160+
"selection": "hidden",
161+
},
162+
)
163+
choose_rrd.change(lambda x: x, inputs=[choose_rrd], outputs=[viewer])
152164

153165

154166
if __name__ == "__main__":

‎demo/space.py

+35-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from app import demo as app
44
import os
55

6-
_docs = {'Rerun': {'description': 'Creates a Rerun viewer component that can be used to display the output of a Rerun stream.', 'members': {'__init__': {'value': {'type': 'list[pathlib.Path | str]\n | pathlib.Path\n | str\n | bytes\n | Callable\n | None', 'default': 'None', 'description': 'Takes a singular or list of RRD resources. Each RRD can be a Path, a string containing a url, or a binary blob containing encoded RRD data. If callable, the function will be called whenever the app loads to set the initial value of the component.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.'}, 'every': {'type': 'float | None', 'default': 'None', 'description': "If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute."}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': 'if True, will display label.'}, 'container': {'type': 'bool', 'default': 'True', 'description': 'If True, will place the component in a container - providing some extra padding around the border.'}, 'scale': {'type': 'int | None', 'default': 'None', 'description': 'relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.'}, 'min_width': {'type': 'int', 'default': '160', 'description': 'minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.'}, 'height': {'type': 'int | str', 'default': '640', 'description': 'height of component in pixels. If a string is provided, will be interpreted as a CSS value. If None, will be set to 640px.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': 'If False, component will be hidden.'}, 'streaming': {'type': 'bool', 'default': 'False', 'description': 'If True, the data should be incrementally yielded from the source as `bytes` returned by calling `.read()` on an `rr.binary_stream()`'}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': 'An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': 'An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'render': {'type': 'bool', 'default': 'True', 'description': 'If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.'}}, 'postprocess': {'value': {'type': 'list[pathlib.Path | str] | pathlib.Path | str | bytes', 'description': 'Expects'}}, 'preprocess': {'return': {'type': 'RerunData | None', 'description': 'A RerunData object.'}, 'value': None}}, 'events': {}}, '__meta__': {'additional_interfaces': {'RerunData': {'source': 'class RerunData(GradioRootModel):\n root: list[FileData | str]'}}, 'user_fn_refs': {'Rerun': ['RerunData']}}}
6+
_docs = {'Rerun': {'description': 'Creates a Rerun viewer component that can be used to display the output of a Rerun stream.', 'members': {'__init__': {'value': {'type': 'list[pathlib.Path | str]\n | pathlib.Path\n | str\n | bytes\n | Callable\n | None', 'default': 'None', 'description': 'Takes a singular or list of RRD resources. Each RRD can be a Path, a string containing a url, or a binary blob containing encoded RRD data. If callable, the function will be called whenever the app loads to set the initial value of the component.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.'}, 'every': {'type': 'float | None', 'default': 'None', 'description': "If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute."}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': 'if True, will display label.'}, 'container': {'type': 'bool', 'default': 'True', 'description': 'If True, will place the component in a container - providing some extra padding around the border.'}, 'scale': {'type': 'int | None', 'default': 'None', 'description': 'relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.'}, 'min_width': {'type': 'int', 'default': '160', 'description': 'minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.'}, 'height': {'type': 'int | str', 'default': '640', 'description': 'height of component in pixels. If a string is provided, will be interpreted as a CSS value. If None, will be set to 640px.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': 'If False, component will be hidden.'}, 'streaming': {'type': 'bool', 'default': 'False', 'description': 'If True, the data should be incrementally yielded from the source as `bytes` returned by calling `.read()` on an `rr.binary_stream()`'}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': 'An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': 'An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'render': {'type': 'bool', 'default': 'True', 'description': 'If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.'}, 'panel_states': {'type': 'dict[str, Any] | None', 'default': 'None', 'description': 'Force viewer panels to a specific state. Any panels set cannot be toggled by the user in the viewer. Panel names are "top", "blueprint", "selection", and "time". States are "hidden", "collapsed", and "expanded".'}}, 'postprocess': {'value': {'type': 'list[pathlib.Path | str] | pathlib.Path | str | bytes', 'description': 'Expects'}}, 'preprocess': {'return': {'type': 'RerunData | None', 'description': 'A RerunData object.'}, 'value': None}}, 'events': {}}, '__meta__': {'additional_interfaces': {'RerunData': {'source': 'class RerunData(GradioRootModel):\n root: list[FileData | str]'}}, 'user_fn_refs': {'Rerun': ['RerunData']}}}
77

88
abs_path = os.path.join(os.path.dirname(__file__), "css.css")
99

@@ -137,6 +137,16 @@ def cleanup_cube_rrds(pending_cleanup):
137137
img = gr.Image(interactive=True, label="Image")
138138
with gr.Column():
139139
stream_blur = gr.Button("Stream Repeated Blur")
140+
with gr.Row():
141+
viewer = Rerun(
142+
streaming=True,
143+
panel_states={
144+
"time": "collapsed",
145+
"blueprint": "hidden",
146+
"selection": "hidden",
147+
},
148+
)
149+
stream_blur.click(streaming_repeated_blur, inputs=[img], outputs=[viewer])
140150
141151
with gr.Tab("Dynamic RRD"):
142152
pending_cleanup = gr.State(
@@ -154,6 +164,20 @@ def cleanup_cube_rrds(pending_cleanup):
154164
)
155165
with gr.Row():
156166
create_rrd = gr.Button("Create RRD")
167+
with gr.Row():
168+
viewer = Rerun(
169+
streaming=True,
170+
panel_states={
171+
"time": "collapsed",
172+
"blueprint": "hidden",
173+
"selection": "hidden",
174+
},
175+
)
176+
create_rrd.click(
177+
create_cube_rrd,
178+
inputs=[x_count, y_count, z_count, pending_cleanup],
179+
outputs=[viewer],
180+
)
157181
158182
with gr.Tab("Hosted RRD"):
159183
with gr.Row():
@@ -167,23 +191,16 @@ def cleanup_cube_rrds(pending_cleanup):
167191
f"{rr.bindings.get_app_url()}/examples/plots.rrd",
168192
],
169193
)
170-
171-
# Rerun 0.16 has issues when embedded in a Gradio tab, so we share a viewer between all the tabs.
172-
# In 0.17 we can instead scope each viewer to its own tab to clean up these examples further.
173-
with gr.Row():
174-
viewer = Rerun(
175-
streaming=True,
176-
)
177-
178-
stream_blur.click(streaming_repeated_blur, inputs=[img], outputs=[viewer])
179-
180-
create_rrd.click(
181-
create_cube_rrd,
182-
inputs=[x_count, y_count, z_count, pending_cleanup],
183-
outputs=[viewer],
184-
)
185-
186-
choose_rrd.change(lambda x: x, inputs=[choose_rrd], outputs=[viewer])
194+
with gr.Row():
195+
viewer = Rerun(
196+
streaming=True,
197+
panel_states={
198+
"time": "collapsed",
199+
"blueprint": "hidden",
200+
"selection": "hidden",
201+
},
202+
)
203+
choose_rrd.change(lambda x: x, inputs=[choose_rrd], outputs=[viewer])
187204
188205
189206
if __name__ == "__main__":

0 commit comments

Comments
 (0)
Please sign in to comment.