VibecoderMcSwaggins's picture
feat: Gradio Custom Component for NiiVue (#29)
227ab66 unverified
metadata
tags:
  - gradio-custom-component
  - Image
title: gradio_niivueviewer
short_description: null
colorFrom: blue
colorTo: yellow
sdk: gradio
pinned: false
app_file: space.py

gradio_niivueviewer

Static Badge

A Gradio custom component for 3D medical imaging visualization using NiiVue (WebGL).

Installation

pip install gradio_niivueviewer

Usage

import gradio as gr
from gradio_niivueviewer import NiiVueViewer

example = NiiVueViewer().example_value()

demo = gr.Interface(
    lambda x: x,
    NiiVueViewer(),  # interactive version of your component
    NiiVueViewer(),  # static version of your component
    # examples=[[example]],  # uncomment this line to view the "example version" of your component
)


if __name__ == "__main__":
    demo.launch()

NiiVueViewer

Initialization

name type default description
value
NiiVueViewerData | dict[str, typing.Any] | None
None None
label
str | None
None None
height
int
500 None
show_label
bool
True None
container
bool
True None
scale
int | None
None None
min_width
int
160 None
visible
bool
True None
elem_id
str | None
None None
elem_classes
list[str] | str | None
None None
render
bool
True None
key
int | str | tuple[int | str, Ellipsis] | None
None None

User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

  • When used as an Input, the component only impacts the input signature of the user function.
  • When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

  • As output: Is passed, the preprocessed input data sent to the user's function in the backend.
  • As input: Should return, the output data received by the component from the user's function in the backend.
def predict(
    value: dict[str, typing.Any] | None
) -> dict[str, typing.Any] | None:
    return value

NiiVueViewerData

class NiiVueViewerData(GradioModel):
    background_url: str | None = None
    overlay_url: str | None = None