1919import itables
2020import pandas
2121import logging
22+ import json
2223from botocore .config import Config
2324from ipywidgets import Button , Output
2425from IPython .display import display
@@ -160,6 +161,7 @@ def _get_model_summary(self, full_summary):
160161 "Model Type" : model_type ,
161162 "Model Description" : full_summary ["HubContentDescription" ],
162163 "Search Keywords" : keywords ,
164+ "Deployment Configs" : self ._create_config_link (full_summary ["HubContentName" ]),
163165 }
164166
165167 def _determine_model_type (self , keywords , model_id ):
@@ -180,6 +182,63 @@ def _get_hub_document(self, model_id):
180182 HubContentType = "Model" ,
181183 HubContentName = model_id
182184 )["HubContentDocument" ]
185+
186+ def _get_supported_instance_types (self , model_id ):
187+ """Extract supported instance types from hub document."""
188+ try :
189+ hub_doc = self ._get_hub_document (model_id )
190+ doc_data = json .loads (hub_doc )
191+
192+ supported_types = doc_data .get ("SupportedInferenceInstanceTypes" , ["ml.g5.8xlarge" ])
193+ default_type = doc_data .get ("DefaultInferenceInstanceType" )
194+
195+ if default_type and default_type in supported_types :
196+ supported_types = [default_type ] + [t for t in supported_types if t != default_type ]
197+
198+ return supported_types
199+ except Exception :
200+ return ["ml.g5.8xlarge" ]
201+
202+ def _create_config_link (self , model_id ):
203+ """Create an HTML link that generates deployment config."""
204+ config_code = self ._generate_deployment_config (model_id ).replace ('\n ' , '\\ n' ).replace ("'" , "\\ '" )
205+ return f'<a href="javascript:void(0)" onclick="navigator.clipboard.writeText(\' { config_code } \' ); alert(\' Config copied to clipboard!\' )" style="color: #007bff; text-decoration: underline;">Get Config</a>'
206+
207+ def _generate_deployment_config (self , model_id ):
208+ """Generate deployment configuration code for a model."""
209+ supported_types = self ._get_supported_instance_types (model_id )
210+ default_type = supported_types [0 ] if supported_types else "ml.g5.8xlarge"
211+
212+ types_comment = f"# Supported instance types: { ', ' .join (supported_types )} "
213+
214+ config_code = f'''# Deployment configuration for { model_id }
215+ from sagemaker.hyperpod.inference.config.hp_jumpstart_endpoint_config import Model, Server, SageMakerEndpoint, TlsConfig
216+ from sagemaker.hyperpod.inference.hp_jumpstart_endpoint import HPJumpStartEndpoint
217+
218+ { types_comment }
219+
220+ # Create configs
221+ model = Model(
222+ model_id='{ model_id } ',
223+ model_version='<specify-version>', # Use latest version or specify version
224+ )
225+ server = Server(
226+ instance_type='{ default_type } ', # Choose from supported types above
227+ )
228+ endpoint_name = SageMakerEndpoint(name='<your-endpoint-name>')
229+ tls_config = TlsConfig(tls_certificate_output_s3_uri='s3://<your-tls-bucket>')
230+
231+ # Create endpoint spec
232+ js_endpoint = HPJumpStartEndpoint(
233+ model=model,
234+ server=server,
235+ sage_maker_endpoint=endpoint_name,
236+ tls_config=tls_config,
237+ )
238+
239+ # Deploy the endpoint
240+ js_endpoint.create()'''
241+ return config_code
183242
184243
185244def get_all_public_hub_model_data (region : str ):
@@ -198,7 +257,7 @@ def interactive_view(tabular_data: list):
198257 styled_df = _style_dataframe (df )
199258 layout = _get_table_layout (len (tabular_data ))
200259
201- itables .show (styled_df , layout = layout )
260+ itables .show (styled_df , layout = layout , allow_html = True )
202261
203262
204263def _configure_itables ():
0 commit comments