DeployModel widget in Supervisely is a comprehensive user interface element that allows users to deploy or connect to neural network models in three different modes:
Connect: Connect to an already deployed model session
Pretrained: Deploy a pretrained model from the Supervisely ecosystem
Custom: Deploy a custom model from your training experiments
This widget streamlines the model deployment workflow and provides a unified interface for managing model sessions in Supervisely apps.
Supervisely API instance for communicating with the Supervisely server. If not provided, will use the default API instance.
type:Api
default value:None (will create new Api instance)
team_id
Team ID for model deployment operations. If not provided, will use the team ID from environment variables.
type:int
default value:None (will use sly.env.team_id())
modes
List of deployment modes to enable in the widget. Can include "connect", "pretrained", and/or "custom". If not provided, all three modes will be available.
import os
import supervisely as sly
from dotenv import load_dotenv
from supervisely.app.widgets import Card, Container, Button, Text, DeployModel, Flexbox
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()
team_id = sly.env.team_id()
# Initialize DeployModel widget with all modes
deploy_model = DeployModel(
api=api,
team_id=team_id,
modes=["connect", "pretrained", "custom"]
)
# Create info text to display deployment parameters
info_text = Text("", status="text")
info_text.hide()
# Create buttons to interact with the widget
get_params_button = Button("Get Deploy Parameters", icon="zmdi zmdi-info")
load_state_button = Button("Load State (Connect to YOLOv8)", icon="zmdi zmdi-download")
buttons_container = Container(
[get_params_button, load_state_button],
direction="horizontal",
gap=10
)
# Create main card
card = Card(
title="Deploy Model",
description="Deploy or connect to a model using different modes",
content=Container([deploy_model, buttons_container, info_text], gap=20),
)
layout = Container(widgets=[card], direction="vertical")
app = sly.Application(layout=layout)
@get_params_button.click
def show_deploy_params():
"""Show current deployment parameters"""
try:
params = deploy_model.get_deploy_parameters()
info_text.set(f"Deploy Parameters: {params}", status="success")
info_text.show()
except Exception as e:
info_text.set(f"Error getting parameters: {str(e)}", status="error")
info_text.show()
@load_state_button.click
def load_example_state():
"""Load example state - select pretrained model"""
try:
# Example: Load state to select a pretrained YOLOv8n model
example_state = {
"mode": "pretrained",
"agent_id": None,
"framework": "yolov8",
"model_name": "yolov8n-seg"
}
deploy_model.load_from_json(example_state)
info_text.set("Loaded example state: YOLOv8n segmentation model", status="success")
info_text.show()
except Exception as e:
info_text.set(f"Error loading state: {str(e)}", status="error")
info_text.show()