{"id":17772984,"url":"https://github.com/radames/gradio-rerun-viewer","last_synced_at":"2025-03-15T16:32:07.124Z","repository":{"id":237057388,"uuid":"793625684","full_name":"radames/gradio-rerun-viewer","owner":"radames","description":"Rerun viewer with Gradio","archived":false,"fork":false,"pushed_at":"2024-10-18T05:31:44.000Z","size":40114,"stargazers_count":14,"open_issues_count":5,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T07:04:27.582Z","etag":null,"topics":["gradio","gradio-custom-component","multimodal","rerun"],"latest_commit_sha":null,"homepage":"https://huggingface.co/spaces/radames/gradio_rerun","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/radames.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-29T15:16:16.000Z","updated_at":"2025-02-05T21:49:16.000Z","dependencies_parsed_at":"2024-10-20T14:15:33.151Z","dependency_job_id":null,"html_url":"https://github.com/radames/gradio-rerun-viewer","commit_stats":null,"previous_names":["radames/gradio-rerun-viewer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radames%2Fgradio-rerun-viewer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radames%2Fgradio-rerun-viewer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radames%2Fgradio-rerun-viewer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radames%2Fgradio-rerun-viewer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radames","download_url":"https://codeload.github.com/radames/gradio-rerun-viewer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243760344,"owners_count":20343625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gradio","gradio-custom-component","multimodal","rerun"],"created_at":"2024-10-26T21:41:48.852Z","updated_at":"2025-03-15T16:32:07.109Z","avatar_url":"https://github.com/radames.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntags: [gradio-custom-component, SimpleImage, multimodal data, visualization, machine learning, robotics]\ntitle: gradio_rerun\nshort_description: Rerun viewer with Gradio\ncolorFrom: blue\ncolorTo: yellow\nsdk: gradio\npinned: false\napp_file: space.py\n---\n\n# `gradio_rerun`\n\u003ca href=\"https://pypi.org/project/gradio_rerun/\" target=\"_blank\"\u003e\u003cimg alt=\"PyPI - Version\" src=\"https://img.shields.io/pypi/v/gradio_rerun\"\u003e\u003c/a\u003e \u003ca href=\"https://github.com/radames/gradio-rerun-viewer/issues\" target=\"_blank\"\u003e\u003cimg alt=\"Static Badge\" src=\"https://img.shields.io/badge/Issues-white?logo=github\u0026logoColor=black\"\u003e\u003c/a\u003e \n\nRerun viewer with Gradio\n\n## Installation\n\n```bash\npip install gradio_rerun\n```\n\n## Usage\n\n```python\nimport cv2\nimport os\nimport tempfile\nimport time\n\nimport gradio as gr\nfrom gradio_rerun import Rerun\n\nimport rerun as rr\nimport rerun.blueprint as rrb\n\nfrom color_grid import build_color_grid\n\n# NOTE: Functions that work with Rerun should be decorated with `@rr.thread_local_stream`.\n# This decorator creates a generator-aware thread-local context so that rerun log calls\n# across multiple workers stay isolated.\n\n\n# A task can directly log to a binary stream, which is routed to the embedded viewer.\n# Incremental chunks are yielded to the viewer using `yield stream.read()`.\n#\n# This is the preferred way to work with Rerun in Gradio since your data can be immediately and\n# incrementally seen by the viewer. Also, there are no ephemeral RRDs to cleanup or manage.\n@rr.thread_local_stream(\"rerun_example_streaming_blur\")\ndef streaming_repeated_blur(img):\n    stream = rr.binary_stream()\n\n    if img is None:\n        raise gr.Error(\"Must provide an image to blur.\")\n\n    blueprint = rrb.Blueprint(\n        rrb.Horizontal(\n            rrb.Spatial2DView(origin=\"image/original\"),\n            rrb.Spatial2DView(origin=\"image/blurred\"),\n        ),\n        collapse_panels=True,\n    )\n\n    rr.send_blueprint(blueprint)\n\n    rr.set_time_sequence(\"iteration\", 0)\n\n    rr.log(\"image/original\", rr.Image(img))\n    yield stream.read()\n\n    blur = img\n\n    for i in range(100):\n        rr.set_time_sequence(\"iteration\", i)\n\n        # Pretend blurring takes a while so we can see streaming in action.\n        time.sleep(0.1)\n        blur = cv2.GaussianBlur(blur, (5, 5), 0)\n\n        rr.log(\"image/blurred\", rr.Image(blur))\n\n        # Each time we yield bytes from the stream back to Gradio, they\n        # are incrementally sent to the viewer. Make sure to yield any time\n        # you want the user to be able to see progress.\n        yield stream.read()\n\n\n# However, if you have a workflow that creates an RRD file instead, you can still send it\n# directly to the viewer by simply returning the path to the RRD file.\n#\n# This may be helpful if you need to execute a helper tool written in C++ or Rust that can't\n# be easily modified to stream data directly via Gradio.\n#\n# In this case you may want to clean up the RRD file after it's sent to the viewer so that you\n# don't accumulate too many  temporary files.\n@rr.thread_local_stream(\"rerun_example_cube_rrd\")\ndef create_cube_rrd(x, y, z, pending_cleanup):\n    cube = build_color_grid(int(x), int(y), int(z), twist=0)\n    rr.log(\"cube\", rr.Points3D(cube.positions, colors=cube.colors, radii=0.5))\n\n    # We eventually want to clean up the RRD file after it's sent to the viewer, so tracking\n    # any pending files to be cleaned up when the state is deleted.\n    temp = tempfile.NamedTemporaryFile(prefix=\"cube_\", suffix=\".rrd\", delete=False)\n    pending_cleanup.append(temp.name)\n\n    blueprint = rrb.Spatial3DView(origin=\"cube\")\n    rr.save(temp.name, default_blueprint=blueprint)\n\n    # Just return the name of the file -- Gradio will convert it to a FileData object\n    # and send it to the viewer.\n    return temp.name\n\n\ndef cleanup_cube_rrds(pending_cleanup):\n    for f in pending_cleanup:\n        os.unlink(f)\n\n\nwith gr.Blocks() as demo:\n    with gr.Tab(\"Streaming\"):\n        with gr.Row():\n            img = gr.Image(interactive=True, label=\"Image\")\n            with gr.Column():\n                stream_blur = gr.Button(\"Stream Repeated Blur\")\n        with gr.Row():\n            viewer = Rerun(\n                streaming=True,\n                panel_states={\n                    \"time\": \"collapsed\",\n                    \"blueprint\": \"hidden\",\n                    \"selection\": \"hidden\",\n                },\n            )\n        stream_blur.click(streaming_repeated_blur, inputs=[img], outputs=[viewer])\n\n    with gr.Tab(\"Dynamic RRD\"):\n        pending_cleanup = gr.State(\n            [], time_to_live=10, delete_callback=cleanup_cube_rrds\n        )\n        with gr.Row():\n            x_count = gr.Number(\n                minimum=1, maximum=10, value=5, precision=0, label=\"X Count\"\n            )\n            y_count = gr.Number(\n                minimum=1, maximum=10, value=5, precision=0, label=\"Y Count\"\n            )\n            z_count = gr.Number(\n                minimum=1, maximum=10, value=5, precision=0, label=\"Z Count\"\n            )\n        with gr.Row():\n            create_rrd = gr.Button(\"Create RRD\")\n        with gr.Row():\n            viewer = Rerun(\n                streaming=True,\n                panel_states={\n                    \"time\": \"collapsed\",\n                    \"blueprint\": \"hidden\",\n                    \"selection\": \"hidden\",\n                },\n            )\n        create_rrd.click(\n            create_cube_rrd,\n            inputs=[x_count, y_count, z_count, pending_cleanup],\n            outputs=[viewer],\n        )\n\n    with gr.Tab(\"Hosted RRD\"):\n        with gr.Row():\n            # It may be helpful to point the viewer to a hosted RRD file on another server.\n            # If an RRD file is hosted via http, you can just return a URL to the file.\n            choose_rrd = gr.Dropdown(\n                label=\"RRD\",\n                choices=[\n                    f\"{rr.bindings.get_app_url()}/examples/arkit_scenes.rrd\",\n                    f\"{rr.bindings.get_app_url()}/examples/dna.rrd\",\n                    f\"{rr.bindings.get_app_url()}/examples/plots.rrd\",\n                ],\n            )\n        with gr.Row():\n            viewer = Rerun(\n                streaming=True,\n                panel_states={\n                    \"time\": \"collapsed\",\n                    \"blueprint\": \"hidden\",\n                    \"selection\": \"hidden\",\n                },\n            )\n        choose_rrd.change(lambda x: x, inputs=[choose_rrd], outputs=[viewer])\n\n\nif __name__ == \"__main__\":\n    demo.launch()\n\n```\n\n## `Rerun`\n\n### Initialization\n\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth align=\"left\"\u003ename\u003c/th\u003e\n\u003cth align=\"left\" style=\"width: 25%;\"\u003etype\u003c/th\u003e\n\u003cth align=\"left\"\u003edefault\u003c/th\u003e\n\u003cth align=\"left\"\u003edescription\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nlist[pathlib.Path | str]\n    | pathlib.Path\n    | str\n    | bytes\n    | Callable\n    | None\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eTakes 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.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003elabel\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nstr | None\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eThe 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.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eevery\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nfloat | None\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eIf `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.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eshow_label\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nbool | None\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eif True, will display label.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003econtainer\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nbool\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eTrue\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eIf True, will place the component in a container - providing some extra padding around the border.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003escale\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nint | None\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003erelative 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.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003emin_width\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nint\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003e160\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eminimum 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.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eheight\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nint | str\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003e640\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eheight of component in pixels. If a string is provided, will be interpreted as a CSS value. If None, will be set to 640px.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003evisible\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nbool\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eTrue\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eIf False, component will be hidden.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003estreaming\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nbool\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eFalse\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eIf True, the data should be incrementally yielded from the source as `bytes` returned by calling `.read()` on an `rr.binary_stream()`\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eelem_id\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nstr | None\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eAn optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eelem_classes\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nlist[str] | str | None\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eAn optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003erender\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\nbool\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eTrue\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eIf 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.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003epanel_states\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\" style=\"width: 25%;\"\u003e\n\n```python\ndict[str, Any] | None\n```\n\n\u003c/td\u003e\n\u003ctd align=\"left\"\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"left\"\u003eForce 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\".\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\u003c/table\u003e\n\n\n\n\n### User function\n\nThe impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).\n\n- When used as an Input, the component only impacts the input signature of the user function.\n- When used as an output, the component only impacts the return signature of the user function.\n\nThe code snippet below is accurate in cases where the component is used as both an input and an output.\n\n- **As output:** Is passed, a RerunData object.\n- **As input:** Should return, expects.\n\n ```python\n def predict(\n     value: RerunData | None\n ) -\u003e list[pathlib.Path | str] | pathlib.Path | str | bytes:\n     return value\n ```\n \n\n## `RerunData`\n```python\nclass RerunData(GradioRootModel):\n    root: list[FileData | str]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradames%2Fgradio-rerun-viewer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradames%2Fgradio-rerun-viewer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradames%2Fgradio-rerun-viewer/lists"}