In this tutorial you will learn how to create Supervisely apps with GUI on pure python using Supervisely app engine and widgets. We will create a simple "Hello, World!" app that will generate names using Text and Button widgets.
Select configuration name Uvicorn that you specified in launch.json from configuration dropdown.
Press green play button or F5 to start debugging.
debug
Hello, World! app
Import libraries
Init API client
Init API for communicating with Supervisely instance. First, we load environment variables with credentials:
Initialize Text and Button widgets.
Create app layout
Prepare a layout for app using Card widget with the content parameter and place 2 widgets that we've just created in the Container widget. Place order in the Container is also important, we want the "hello text" to be above the name generation button.
Create app using layout
Create an app object with layout parameter.
Layout
Handle button clicks
Use the decorator as shown below to handle button click. When we change hello_msg.text value, data will be pushed to web browser via web sockets.
{
"version": "0.2.0",
"configurations": [
{
"name": "Uvicorn", # ⬅️ Configuration name to select from the dropdown menu in "Run and Debug" section
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"hello_world.src.main:app", # ⬅️ Path to your script
"--host",
"0.0.0.0",
"--port",
"8000",
"--ws",
"websockets",
"--reload"
],
"jinja": true,
"justMyCode": true,
"env": {
"PYTHONPATH": "${workspaceFolder}:${PYTHONPATH}",
"LOG_LEVEL": "DEBUG",
}
}
]
}
import os
import names # requires
import supervisely as sly
from dotenv import load_dotenv
from supervisely.app.widgets import Button, Card, Container, Text
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()