Skip to main content

Python library for easily interacting with trained machine learning models

Project description

gradio_niivueviewer

Static Badge

Python library for easily interacting with trained machine learning models

Installation

pip install gradio_niivueviewer

Usage

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
list[str] | None
value = None List of NIfTI file paths. First path = main volume; second path
seg_labels
dict[int, str] | None
value = None Mapping of integer label value → display name for the
label
str | I18nData | None
value = None Label displayed above the component.
every
'Timer | float | None'
value = None Timer or interval (seconds) to periodically refresh a dynamic value.
inputs
'Component | Sequence[Component] | set[Component] | None'
value = None Components whose changes trigger a value recalculation.
show_label
bool | None
value = None Whether to display the label.
container
bool
value = True Wrap in a padded container.
scale
int | None
value = None Relative width when placed in a Row.
min_width
int
value = 160 Minimum pixel width.
visible
bool | Literal['hidden']
value = True Visibility of the component.
elem_id
str | None
value = None HTML id attribute for the component's root element.
elem_classes
list[str] | str | None
value = None HTML class(es) for the component's root element.
render
bool
value = True If False, defer rendering until later.
key
int | str | tuple[int | str, ...] | None
value = None Stable key for gr.render() re-render identity.
preserved_by_key
list[str] | str | None
value = "value" Constructor parameters preserved across re-renders.

Events

name description
change Triggered when the value of the NiiVueViewer changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input.

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, list of local file paths, or None.
  • As input: Should return, list of NIfTI file paths (absolute or relative to cwd).
def predict(
    value: list[str]| None
) -> list[str]| None:
    return value

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_niivueviewer-0.0.1.tar.gz (233.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradio_niivueviewer-0.0.1-py3-none-any.whl (93.6 kB view details)

Uploaded Python 3

File details

Details for the file gradio_niivueviewer-0.0.1.tar.gz.

File metadata

  • Download URL: gradio_niivueviewer-0.0.1.tar.gz
  • Upload date:
  • Size: 233.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for gradio_niivueviewer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 06955e960cdea04abc14ee45ae883b0e3511876797b61cd2dcf001b003c94413
MD5 f577269fa545f9c5967ffa40d4ce7a91
BLAKE2b-256 fb8bf50ce43a6d5cb5e13958093c8340379e4ffe6aa82eb79c2f12d880a5e1cb

See more details on using hashes here.

File details

Details for the file gradio_niivueviewer-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_niivueviewer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4b69c039931d7ff2d51aee6b8b20789f5070053e077e4f2f1ec662f32c81c06e
MD5 a711f30b9d1bf7517c81a2f8119c6b49
BLAKE2b-256 44f41c54edeab519116b099fb752b454d4829d0b9ed4695d2c6ee0951e5c1d05

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page