|
|
--- |
|
|
tags: [gradio-custom-component, Image] |
|
|
title: gradio_niivueviewer |
|
|
short_description: |
|
|
colorFrom: blue |
|
|
colorTo: yellow |
|
|
sdk: gradio |
|
|
pinned: false |
|
|
app_file: space.py |
|
|
--- |
|
|
|
|
|
# `gradio_niivueviewer` |
|
|
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange"> |
|
|
|
|
|
A Gradio custom component for 3D medical imaging visualization using NiiVue (WebGL). |
|
|
|
|
|
## Installation |
|
|
|
|
|
```bash |
|
|
pip install gradio_niivueviewer |
|
|
``` |
|
|
|
|
|
## Usage |
|
|
|
|
|
```python |
|
|
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 |
|
|
|
|
|
<table> |
|
|
<thead> |
|
|
<tr> |
|
|
<th align="left">name</th> |
|
|
<th align="left" style="width: 25%;">type</th> |
|
|
<th align="left">default</th> |
|
|
<th align="left">description</th> |
|
|
</tr> |
|
|
</thead> |
|
|
<tbody> |
|
|
<tr> |
|
|
<td align="left"><code>value</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
NiiVueViewerData | dict[str, typing.Any] | None |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>None</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>label</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
str | None |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>None</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>height</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
int |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>500</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>show_label</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
bool |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>True</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>container</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
bool |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>True</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>scale</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
int | None |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>None</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>min_width</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
int |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>160</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>visible</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
bool |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>True</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>elem_id</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
str | None |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>None</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>elem_classes</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
list[str] | str | None |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>None</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>render</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
bool |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>True</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td align="left"><code>key</code></td> |
|
|
<td align="left" style="width: 25%;"> |
|
|
|
|
|
```python |
|
|
int | str | tuple[int | str, Ellipsis] | None |
|
|
``` |
|
|
|
|
|
</td> |
|
|
<td align="left"><code>None</code></td> |
|
|
<td align="left">None</td> |
|
|
</tr> |
|
|
</tbody></table> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 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. |
|
|
|
|
|
```python |
|
|
def predict( |
|
|
value: dict[str, typing.Any] | None |
|
|
) -> dict[str, typing.Any] | None: |
|
|
return value |
|
|
``` |
|
|
|
|
|
|
|
|
## `NiiVueViewerData` |
|
|
```python |
|
|
class NiiVueViewerData(GradioModel): |
|
|
background_url: str | None = None |
|
|
overlay_url: str | None = None |
|
|
``` |
|
|
|