Created
March 26, 2025 18:30
-
-
Save pablovela5620/555da1b735d077f997a88d7d24881569 to your computer and use it in GitHub Desktop.
Simplified app.py for rerun callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import gradio as gr | |
| from gradio_rerun import Rerun | |
| from gradio_rerun.events import SelectionChange, TimeUpdate, TimelineChange, EntitySelection | |
| import rerun as rr | |
| import rerun.blueprint as rrb | |
| def streaming_repeated_blur_per_user(img): | |
| recording = rr.RecordingStream("rerun_example_callbacks", recording_id="streaming_repeated_blur") | |
| stream = recording.binary_stream() | |
| if img is None: | |
| raise gr.Error("Must provide an image to blur.") | |
| blueprint = rrb.Blueprint( | |
| rrb.Horizontal( | |
| rrb.Spatial2DView(origin="image/original"), | |
| rrb.Spatial2DView(origin="image/blurred"), | |
| ), | |
| collapse_panels=True, | |
| ) | |
| recording.send_blueprint(blueprint) | |
| recording.set_time_sequence("iteration", 0) | |
| recording.log("image/original", rr.Image(img)) | |
| yield stream.read() | |
| with gr.Blocks() as demo: | |
| with gr.Tab("Streaming"): | |
| with gr.Row(): | |
| img = gr.Image(interactive=True, label="Image") | |
| with gr.Column(): | |
| stream_blur = gr.Button("Stream Repeated Blur") | |
| with gr.Row(): | |
| viewer = Rerun( | |
| streaming=True, | |
| panel_states={ | |
| "time": "collapsed", | |
| "blueprint": "hidden", | |
| "selection": "hidden", | |
| }, | |
| ) | |
| stream_blur.click(streaming_repeated_blur_per_user, inputs=[img], outputs=[viewer]) | |
| def on_selection_change(evt: SelectionChange): | |
| print("selection change", evt.items) | |
| for item in evt.items: | |
| match item: | |
| case EntitySelection(): | |
| stream = rr.RecordingStream("rerun_example_callbacks", recording_id="streaming_repeated_blur") | |
| print("logging") | |
| print(item.position[0:2]) | |
| stream.log(f"{item.entity_path}/keypoint", rr.Points2D(item.position[0:2], radii=5)) | |
| def on_time_update(evt: TimeUpdate): | |
| print("time update", evt.time) | |
| def on_timeline_change(evt: TimelineChange): | |
| print("timeline change", evt.timeline, evt.time) | |
| viewer.selection_change(on_selection_change) | |
| viewer.time_update(on_time_update) | |
| viewer.timeline_change(on_timeline_change) | |
| if __name__ == "__main__": | |
| demo.launch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment