diff --git a/.gitignore b/.gitignore index 847c4fa..510bf9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/secret_debug.env +.venv +.DS_Store diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8d37bb9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": true, + "env": { + "PYTHONPATH": "${workspaceFolder}:${PYTHONPATH}" + } + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e7343c6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,18 @@ +{ + "python.defaultInterpreterPath": ".venv/bin/python", + "files.exclude": { + "**/__pycache__": true, + ".venv": true + }, + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.formatOnType": true, + "[html]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "python.formatting.provider": "black", + "debug.inlineValues": "off", +} \ No newline at end of file diff --git a/README.md b/README.md index aae9c51..6753c10 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ -# hello-world-app -Supervisely hello world app - use it as a template for your custom appliation or for debug purposes + +
+ + +# Hello World App + +

+ Overview • + How To Use +

+ +
+ +# Overview + +Explain here what your app does. + +# How to use + +Step by step guide with examples and demos \ No newline at end of file diff --git a/config.json b/config.json index c705bf3..2033e49 100644 --- a/config.json +++ b/config.json @@ -1,19 +1,11 @@ { - "name": "Hello World App", + "name": "Hello World!", "type": "app", - "categories": [ - "development" - ], - "description": "Working demo, use it as a template for your custom apps", - "docker_image": "supervisely/base-py-sdk:6.35.0", - "main_script": "src/my_main_script.py", - "modal_template": "src/modal.html", - "modal_template_state": { - "length": 5 - }, - "gui_template": "src/gui.html", - "task_location": "application_sessions", - "isolate": true, - "icon": "https://img.icons8.com/fluent/96/000000/source-code.png", + "categories": ["development"], + "description": "Demonstrates how to turn your python script into Supervisely App", + "docker_image": "supervisely/base-py-sdk:6.50.0", + "main_script": "src/main.py", + "task_location": "workspace_tasks", + "icon": "https://user-images.githubusercontent.com/12828725/182186256-5ee663ad-25c7-4a62-9af1-fbfdca715b57.png", "icon_background": "#FFFFFF" -} \ No newline at end of file +} diff --git a/create_venv.sh b/create_venv.sh new file mode 100755 index 0000000..498b4b6 --- /dev/null +++ b/create_venv.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# learn more in documentation +# Official python docs: https://docs.python.org/3/library/venv.html +# Superviely developer portal: https://developer.supervise.ly/getting-started/installation#venv + +if [ -d "venv" ]; then + echo "VENV already exists, will be removed" + rm -rf .venv +fi + +echo "VENV will be created" && \ +python3 -m venv .venv && \ +source .venv/bin/activate && \ + +echo "Install requirements..." && \ +pip3 install -r requirements.txt && \ +echo "Requirements have been successfully installed" && \ +deactivate \ No newline at end of file diff --git a/debug.env b/debug.env deleted file mode 100644 index 76e4be7..0000000 --- a/debug.env +++ /dev/null @@ -1,9 +0,0 @@ -PYTHONUNBUFFERED=1 -modal.state.teamId=91 -modal.state.workspaceId=157 -modal.state.length=10 -TASK_ID=678 -SERVER_ADDRESS="put your value here in secret_debug.env" -API_TOKEN="put your value here in secret_debug.env" -AGENT_TOKEN="put your value here in secret_debug.env" - diff --git a/local.env b/local.env new file mode 100644 index 0000000..5e0071c --- /dev/null +++ b/local.env @@ -0,0 +1 @@ +context.userLogin="max" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ea8f72e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +supervisely==6.50.0 + +# used to print cool text to stdout +art==5.7 + +# my favorite code formatter +black==22.6.0 diff --git a/secret_debug_example.env b/secret_debug_example.env deleted file mode 100644 index 686b8d9..0000000 --- a/secret_debug_example.env +++ /dev/null @@ -1,3 +0,0 @@ -SERVER_ADDRESS="xxx" -API_TOKEN="xxx" -AGENT_TOKEN="xxx" \ No newline at end of file diff --git a/src/gui.html b/src/gui.html deleted file mode 100644 index 90ce70c..0000000 --- a/src/gui.html +++ /dev/null @@ -1,18 +0,0 @@ -
- - - - - - - Generate! - - - - - -
Generated string: {{data.randomString}}
-
-
-
-
\ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..4099b68 --- /dev/null +++ b/src/main.py @@ -0,0 +1,17 @@ +import os +import supervisely as sly +from dotenv import load_dotenv +from art import tprint + +load_dotenv("local.env") + + +def main(): + name = os.environ["context.userLogin"] + print("Hello World!") + print("This app is run by user:") + tprint(name) + + +if __name__ == "__main__": + main() diff --git a/src/modal.html b/src/modal.html deleted file mode 100644 index 0a63833..0000000 --- a/src/modal.html +++ /dev/null @@ -1,6 +0,0 @@ -
- - - -
\ No newline at end of file diff --git a/src/my_main_script.py b/src/my_main_script.py deleted file mode 100644 index 2f4af40..0000000 --- a/src/my_main_script.py +++ /dev/null @@ -1,52 +0,0 @@ -import os -import random -import string -import supervisely_lib as sly - - -my_app = sly.AppService() - -LENGTH = int(os.environ['modal.state.length']) - - -@my_app.callback("generate") -@sly.timeit -def generate_random_string(api: sly.Api, task_id, context, state, app_logger): - rand_string = ''.join((random.choice(string.ascii_letters + string.digits)) for _ in range(LENGTH)) - rand_string = state["prefix"] + rand_string - api.task.set_field(task_id, "data.randomString", rand_string) - - -@my_app.callback("preprocessing") -@sly.timeit -def preprocessing(api: sly.Api, task_id, context, state, app_logger): - sly.logger.info("do something here") - - -def main(): - sly.logger.info("Script arguments from modal dialog box", extra={"length: ": LENGTH}) - - api = sly.Api.from_env() - - data = { - "randomString": "hello!" - } - - state = { - "prefix": "abc_" - } - - initial_events = [ - { - "state": None, - "context": None, - "command": "preprocessing", - } - ] - - # Run application service - my_app.run(data=data, state=state, initial_events=initial_events) - - -if __name__ == "__main__": - sly.main_wrapper("main", main) \ No newline at end of file