Skip to content

Commit ca4eb06

Browse files
Stop using download_url in item viewer
1 parent 4536e6f commit ca4eb06

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

src/aignostics/application/_gui/_page_application_run_describe.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
)
1616
from nicegui import run as nicegui_run
1717

18-
from aignostics.platform import ItemOutput, ItemResult, ItemState, RunState
18+
from aignostics.platform import ItemOutput, ItemResult, ItemState, RunState, Run
1919
from aignostics.third_party.showinfm.showinfm import show_in_file_manager
2020
from aignostics.utils import GUILocalFilePicker, get_user_data_directory
21+
from aignx.codegen.models import ArtifactOutput
2122

2223
if TYPE_CHECKING:
2324
from aignx.codegen.models import RunReadResponse
@@ -430,9 +431,10 @@ def csv_view_dialog_content(title: str | None, url: str | None) -> None:
430431
with ui.row(align_items="end").classes("w-full"), ui.column(align_items="end").classes("w-full"):
431432
ui.button("Close", on_click=csv_view_dialog.close)
432433

433-
def csv_dialog_open(title: str, url: str) -> None:
434+
def csv_dialog_open(title: str, artifact_id: str) -> None:
434435
"""Open the CSV dialog."""
435-
csv_view_dialog_content.refresh(title=title, url=url)
436+
download_url = Run.for_run_id(run_id).get_artifact_download_url(artifact_id)
437+
csv_view_dialog_content.refresh(title=title, url=download_url)
436438
csv_view_dialog.open()
437439

438440
@ui.refreshable
@@ -478,15 +480,16 @@ def tiff_view_dialog_content(title: str | None, url: str | None) -> None:
478480
with ui.row(align_items="end").classes("w-full"), ui.column(align_items="end").classes("w-full"):
479481
ui.button("Close", on_click=tiff_view_dialog.close)
480482

481-
def tiff_dialog_open(title: str, url: str) -> None:
483+
def tiff_dialog_open(title: str, artifact_id: str) -> None:
482484
"""Open the TIFF dialog.
483485
484486
Args:
485487
title (str): The title of the TIFF dialog.
486-
url (str): The URL of the TIFF image.
488+
artifact_id: (str): The ID of the artifact containing the TIFF to display.
487489
488490
"""
489-
tiff_view_dialog_content.refresh(title=title, url=url)
491+
download_url = Run.for_run_id(run_id).get_artifact_download_url(artifact_id)
492+
tiff_view_dialog_content.refresh(title=title, url=download_url)
490493
tiff_view_dialog.open()
491494

492495
@ui.refreshable
@@ -516,6 +519,10 @@ def custom_metadata_dialog_open(title: str, custom_metadata: dict[str, Any]) ->
516519
custom_metadata_dialog_content.refresh(title=title, custom_metadata=custom_metadata)
517520
custom_metadata_dialog.open()
518521

522+
def open_browser(_, artifact_id):
523+
download_url = Run.for_run_id(run_id).get_artifact_download_url(artifact_id)
524+
webbrowser.open(download_url)
525+
519526
async def open_qupath(
520527
project: Path | None = None, image: Path | str | None = None, button: ui.button | None = None
521528
) -> None:
@@ -760,29 +767,28 @@ def render_item(item: ItemResult) -> None: # noqa: C901, PLR0912, PLR0915
760767
icon=mime_type_to_icon(mime_type),
761768
group="artifacts",
762769
).classes("w-full"):
763-
if artifact.download_url:
764-
url = artifact.download_url
770+
if artifact.output == ArtifactOutput.AVAILABLE:
771+
artifact_id = artifact.output_artifact_id
765772
title = artifact.name
766773
metadata = artifact.metadata
767774
with ui.button_group():
768775
if mime_type == "image/tiff":
769776
ui.button(
770777
"Preview",
771778
icon=mime_type_to_icon(mime_type),
772-
on_click=lambda _, url=url, title=title: tiff_dialog_open(title, url),
779+
on_click=lambda _, artifact_id=artifact_id, title=title: tiff_dialog_open(title, artifact_id),
773780
)
774781
if mime_type == "text/csv":
775782
ui.button(
776783
"Preview",
777784
icon=mime_type_to_icon(mime_type),
778-
on_click=lambda _, url=url, title=title: csv_dialog_open(title, url),
779-
)
780-
if url:
781-
ui.button(
782-
text="Download",
783-
icon="cloud_download",
784-
on_click=lambda _, url=url: webbrowser.open(url),
785+
on_click=lambda _, artifact_id=artifact_id, title=title: csv_dialog_open(title, artifact_id),
785786
)
787+
ui.button(
788+
text="Download",
789+
icon="cloud_download",
790+
on_click=lambda _, artifact_id=artifact_id: open_browser(_, artifact_id),
791+
)
786792
if metadata:
787793
ui.button(
788794
text="Schema",

src/aignostics/application/_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ def _retrieve_and_print_run_items(run_handle: Run, summarize: bool = False) -> N
325325
f"\n - Name: {artifact.name}"
326326
f"\n MIME Type: {get_mime_type_for_artifact(artifact)}"
327327
f"\n Artifact ID: {artifact.output_artifact_id}"
328-
f"\n Download URL: {artifact.download_url}"
329328
)
330329
item_output += artifacts_output
331330

0 commit comments

Comments
 (0)