22# Licensed under the Apache License, Version 2.0 (the "License");
33# http://www.apache.org/licenses/LICENSE-2.0
44#
5- from typing import Optional , Tuple
5+ from typing import Optional , Tuple , Union
66
77from lightning_sdk .api .teamspace_api import UploadedModelInfo
8+ from lightning_sdk .lightning_cloud .env import LIGHTNING_CLOUD_URL
89from lightning_sdk .teamspace import Teamspace
910from lightning_sdk .utils import resolve as sdk_resolvers
1011
1516# else:
1617# LightningModule = None
1718
19+ _SHOWED_MODEL_LINKS = []
20+
1821
1922def _parse_name (name : str ) -> Tuple [str , str , str ]:
2023 """Parse the name argument into its components."""
@@ -50,11 +53,34 @@ def _get_teamspace(name: str, organization: str) -> Teamspace:
5053 return Teamspace (** teamspaces [requested_teamspace ])
5154
5255
56+ def _print_model_link (org_name : str , teamspace_name : str , model_name : str , verbose : Union [bool , int ]) -> None :
57+ """Print a link to the uploaded model.
58+
59+ Args:
60+ org_name: Name of the organization.
61+ teamspace_name: Name of the teamspace.
62+ model_name: Name of the model.
63+ verbose: Whether to print the link:
64+
65+ - If set to 0, no link will be printed.
66+ - If set to 1, the link will be printed only once.
67+ - If set to 2, the link will be printed every time.
68+ """
69+ url = f"{ LIGHTNING_CLOUD_URL } /{ org_name } /{ teamspace_name } /models/{ model_name } "
70+ msg = f"Model uploaded successfully. Link to the model: '{ url } '"
71+ if int (verbose ) > 1 :
72+ print (msg )
73+ elif url not in _SHOWED_MODEL_LINKS :
74+ print (msg )
75+ _SHOWED_MODEL_LINKS .append (url )
76+
77+
5378def upload_model_files (
5479 name : str ,
5580 path : str ,
5681 progress_bar : bool = True ,
5782 cluster_id : Optional [str ] = None ,
83+ verbose : Union [bool , int ] = 0 ,
5884) -> UploadedModelInfo :
5985 """Upload a local checkpoint file to the model store.
6086
@@ -65,16 +91,20 @@ def upload_model_files(
6591 progress_bar: Whether to show a progress bar for the upload.
6692 cluster_id: The name of the cluster to use. Only required if it can't be determined
6793 automatically.
94+ verbose: Whether to print a link to the uploaded model. If set to 0, no link will be printed.
6895
6996 """
7097 org_name , teamspace_name , model_name = _parse_name (name )
7198 teamspace = _get_teamspace (name = teamspace_name , organization = org_name )
72- return teamspace .upload_model (
99+ info = teamspace .upload_model (
73100 path = path ,
74101 name = model_name ,
75102 progress_bar = progress_bar ,
76103 cluster_id = cluster_id ,
77104 )
105+ if verbose :
106+ _print_model_link (org_name , teamspace_name , model_name , verbose )
107+ return info
78108
79109
80110def download_model_files (
0 commit comments