# `gradio_niivueviewer`
Python library for easily interacting with trained machine learning models
## Installation
```bash
pip install gradio_niivueviewer
```
## Usage
```python
import os
import gradio as gr
from gradio_niivueviewer import NiiVueViewer
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
nii_path = os.path.join(ROOT, "input/FLARE_02510_0000.nii.gz")
seg_path = os.path.join(ROOT, "output/FLARE_02510.nii.gz")
# FLARE22 standard organ labels
FLARE_LABELS = {
1: "Liver",
2: "Right Kidney",
3: "Spleen",
4: "Pancreas",
5: "Aorta",
6: "IVC",
7: "Right Adrenal",
8: "Left Adrenal",
9: "Gallbladder",
10: "Esophagus",
11: "Stomach",
12: "Duodenum",
13: "Left Kidney",
}
with gr.Blocks(title="NiiVue Medical Image Viewer") as demo:
gr.Markdown("## NiiVue — FLARE_02510")
NiiVueViewer(value=[nii_path, seg_path], seg_labels=FLARE_LABELS)
if __name__ == "__main__":
demo.launch(
server_port=7870,
allowed_paths=[os.path.dirname(nii_path), os.path.dirname(seg_path)],
)
```
## `NiiVueViewer`
### Initialization
| name | type | default | description |
|---|---|---|---|
value |
```python list[str] | None ``` | value = None |
List of NIfTI file paths. First path = main volume; second path |
seg_labels |
```python dict[int, str] | None ``` | value = None |
Mapping of integer label value → display name for the |
label |
```python str | I18nData | None ``` | value = None |
Label displayed above the component. |
every |
```python 'Timer | float | None' ``` | value = None |
Timer or interval (seconds) to periodically refresh a dynamic value. |
inputs |
```python 'Component | Sequence[Component] | set[Component] | None' ``` | value = None |
Components whose changes trigger a value recalculation. |
show_label |
```python bool | None ``` | value = None |
Whether to display the label. |
container |
```python bool ``` | value = True |
Wrap in a padded container. |
scale |
```python int | None ``` | value = None |
Relative width when placed in a Row. |
min_width |
```python int ``` | value = 160 |
Minimum pixel width. |
visible |
```python bool | Literal['hidden'] ``` | value = True |
Visibility of the component. |
elem_id |
```python str | None ``` | value = None |
HTML id attribute for the component's root element. |
elem_classes |
```python list[str] | str | None ``` | value = None |
HTML class(es) for the component's root element. |
render |
```python bool ``` | value = True |
If False, defer rendering until later. |
key |
```python int | str | tuple[int | str, ...] | None ``` | value = None |
Stable key for gr.render() re-render identity. |
preserved_by_key |
```python list[str] | str | None ``` | value = "value" |
Constructor parameters preserved across re-renders. |