Skip to content

Commit 65b5264

Browse files
committed
Expose server host and port in dataset viewer CLI
Signed-off-by: Ahmad Kiswani <kiswani.ahmad@gmail.com>
1 parent d8ecb8b commit 65b5264

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

docs/get-started/rollout-collection.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,21 @@ Launch the rollout viewer:
122122
ng_viewer +jsonl_fpath=results/simple_weather_rollouts.jsonl
123123
```
124124

125-
Then visit <http://127.0.0.1:7860>
125+
The viewer starts on port 7860 and accepts requests from anywhere by default. Visit <http://SERVER_ADDRESS:7860> in your browser.
126+
127+
:::{tip}
128+
**Configuring Network Access**
129+
130+
By default, the viewer accepts requests from anywhere (`server_host=0.0.0.0`), making it accessible on your local network. To restrict access:
131+
132+
```bash
133+
# Accept requests only from localhost (more secure)
134+
ng_viewer +jsonl_fpath=results/simple_weather_rollouts.jsonl +server_host=127.0.0.1
135+
136+
# Use a custom port
137+
ng_viewer +jsonl_fpath=results/simple_weather_rollouts.jsonl +server_port=8080
138+
```
139+
:::
126140

127141
The viewer shows each rollout with:
128142

docs/reference/cli-commands.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,25 @@ Launch a Gradio interface to view and explore dataset rollouts interactively.
243243
* - `jsonl_fpath`
244244
- str
245245
- Filepath to a local JSONL file to view.
246+
* - `server_host`
247+
- str
248+
- Network address where the viewer accepts requests. Set to `"0.0.0.0"` to accept requests from anywhere (default), or `"127.0.0.1"` to accept requests only from localhost. Can be set by environment variable `GRADIO_SERVER_NAME`.
249+
* - `server_port`
250+
- int
251+
- Port where the viewer accepts requests. Default: `7860`. If the specified port is unavailable, Gradio will search for the next available port. Can be set by environment variable `GRADIO_SERVER_PORT`.
246252
```
247253

248-
**Example**
254+
**Examples**
249255

250256
```bash
257+
# Launch viewer with default settings (accepts requests from anywhere)
251258
ng_viewer +jsonl_fpath=weather_rollouts.jsonl
259+
260+
# Accept requests only from localhost (more secure)
261+
ng_viewer +jsonl_fpath=weather_rollouts.jsonl +server_host=127.0.0.1
262+
263+
# Use a custom port
264+
ng_viewer +jsonl_fpath=weather_rollouts.jsonl +server_port=8080
252265
```
253266

254267
---

nemo_gym/dataset_viewer.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,26 @@ class JsonlDatasetViewerConfig(BaseNeMoGymCLIConfig):
212212
Examples:
213213
214214
```bash
215+
# Accept requests from anywhere (default)
215216
ng_viewer +jsonl_fpath=weather_rollouts.jsonl
217+
218+
# Accept requests only from localhost
219+
ng_viewer +jsonl_fpath=weather_rollouts.jsonl +server_host=127.0.0.1
220+
221+
# Use a custom port
222+
ng_viewer +jsonl_fpath=weather_rollouts.jsonl +server_port=8080
216223
```
217224
"""
218225

219226
jsonl_fpath: str = Field(description="Filepath to a local jsonl file to view.")
227+
server_host: str = Field(
228+
default="0.0.0.0",
229+
description='Network address where the viewer accepts requests. Set to "0.0.0.0" to accept requests from anywhere (default), or "127.0.0.1" to accept requests only from localhost. Can be set by environment variable GRADIO_SERVER_NAME.',
230+
)
231+
server_port: int = Field(
232+
default=7860,
233+
description="Port where the viewer accepts requests. If the specified port is unavailable, Gradio will search for the next available port. Can be set by environment variable GRADIO_SERVER_PORT.",
234+
)
220235

221236

222237
def get_aggregate_metrics(data: List[DatasetViewerVerifyResponse]) -> Dict[str, Any]:
@@ -281,4 +296,4 @@ def select_item(value: int):
281296
def main(): # pragma: no cover
282297
config = JsonlDatasetViewerConfig.model_validate(get_global_config_dict())
283298
demo = build_jsonl_dataset_viewer(config)
284-
demo.launch(enable_monitoring=False)
299+
demo.launch(server_name=config.server_host, server_port=config.server_port, enable_monitoring=False)

0 commit comments

Comments
 (0)