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,84 @@ 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" , [])
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 {"types" : supported_types , "default" : default_type , "error" : None }
199+ except Exception as e :
200+ return {"types" : [], "default" : None , "error" : str (e )}
201+
202+ def _create_config_link (self , model_id ):
203+ """Create deployment config display using collapsible details for all environments."""
204+ return f'<details><summary style="color: #007bff; cursor: pointer;">View SDK Config</summary><pre style="font-size: 10px; background: #f5f5f5; padding: 5px; margin: 5px 0;">{ self ._generate_deployment_config (model_id )} </pre></details>'
205+
206+ def _generate_deployment_config (self , model_id ):
207+ """Generate deployment configuration code for a model."""
208+ instance_data = self ._get_supported_instance_types (model_id )
209+ supported_types = instance_data ["types" ]
210+ default_type = instance_data ["default" ]
211+ error = instance_data ["error" ]
212+
213+ if error :
214+ instance_type = '<ENTER-INSTANCE-TYPE>'
215+ types_comment = ""
216+ else :
217+ instance_type = default_type if default_type else '\<ENTER-INSTANCE-TYPE\>'
218+ types_comment = self ._format_instance_types_comment (supported_types )
219+
220+ config_code = f'''# Deployment configuration for { model_id }
221+ from sagemaker.hyperpod.inference.config.hp_jumpstart_endpoint_config import (
222+ Model, Server, SageMakerEndpoint
223+ )
224+ from sagemaker.hyperpod.inference.hp_jumpstart_endpoint import HPJumpStartEndpoint
225+
226+ { types_comment }
227+
228+ # Create configs - REPLACE PLACEHOLDER VALUE BELOW
229+ model = Model(
230+ model_id='{ model_id } ',
231+ )
232+ server = Server(
233+ instance_type='{ instance_type } ',
234+ )
235+ endpoint_name = SageMakerEndpoint(name='ENTER-YOUR-ENDPOINT-NAME')
236+
237+ # Create endpoint spec
238+ js_endpoint = HPJumpStartEndpoint(
239+ model=model,
240+ server=server,
241+ sage_maker_endpoint=endpoint_name,
242+ )
243+
244+ # Deploy the endpoint
245+ js_endpoint.create()'''
246+ return config_code
247+
248+ def _format_instance_types_comment (self , supported_types ):
249+ """Format instance types comment with line breaks for better readability."""
250+ if not supported_types :
251+ return "# No supported instance types found"
252+
253+ if len (supported_types ) <= 5 :
254+ return f"# Supported instance types: { ', ' .join (supported_types )} "
255+
256+ # For more than 5 instance types, format with newlines every 5 types
257+ comment_lines = ["# Supported instance types:" ]
258+ for i in range (0 , len (supported_types ), 5 ):
259+ batch = supported_types [i :i + 5 ]
260+ comment_lines .append (f"# { ', ' .join (batch )} " )
261+
262+ return '\n ' .join (comment_lines )
183263
184264
185265def get_all_public_hub_model_data (region : str ):
@@ -198,14 +278,14 @@ def interactive_view(tabular_data: list):
198278 styled_df = _style_dataframe (df )
199279 layout = _get_table_layout (len (tabular_data ))
200280
201- itables .show (styled_df , layout = layout )
281+ itables .show (styled_df , layout = layout , allow_html = True )
202282
203283
204284def _configure_itables ():
205285 """Configure itables for notebook display."""
206286 itables .init_notebook_mode (all_interactive = True )
207287 itables .options .allow_html = True
208-
288+
209289
210290def _style_dataframe (df ):
211291 """Apply styling to dataframe."""
@@ -216,4 +296,4 @@ def _style_dataframe(df):
216296
217297def _get_table_layout (data_length ):
218298 """Get appropriate table layout based on data size."""
219- return {} if data_length > 10 else {"topStart" : None , "topEnd" : "search" }
299+ return {} if data_length > 10 else {"topStart" : None , "topEnd" : "search" }
0 commit comments