Skip to main content

SingTown AI Python Client

Project description

SingTown AI Python SDK

This SDK is designed to interact with SingTown AI Cloud Service or SingTown AI Standalone(self-hosted).

Installation

pip install singtown_ai

Usage

Login Configuration

  • SingTown AI Cloud Service: The host is "https://ai.singtown.com".
  • SingTown AI Standalone (self-hosted): The host is something like "http://127.0.0.1:8000".

You can obtain the token and task_id from Project -> Information.

Environment Variables:

export SINGTOWN_AI_HOST="https://ai.singtown.com"  # Or the cloud service URL
export SINGTOWN_AI_TOKEN="your token"            # Your token
export SINGTOWN_AI_TASK_ID="your id"             # Your task ID

Alternatively, set them directly in code:

SingTownAiClient(
  host="https://ai.singtown.com",  # Or the cloud service URL
  token="your token",            # Your token
  task_id="your id"              # Your task ID
)

Dry Run

python -m singtown_ai.dryrun --host=http://127.0.0.1:8000 --token=012345 --task_id=1
  • This command will simulate 10s train task.

Basic Usage

from singtown_ai import SingTownAiClient

with SingTownAiClient() as client:
    pass  # Insert your code here
  • This will periodically update the running status. After finished, it will post a "training succeeded" status. If an error occurs, it will post a "training failed" status.

Mock Usage

from singtown_ai import SingTownAiClient
mock_data = {
    "task": {
        "project": {
            "labels": ["cat", "dog"],
            "type": "CLASSIFICATION",
        },
        "device": "openmv-cam-h7-plus",
        "model_name": "mobilenet_v2_0.35_128",
        "freeze_backbone": True,
        "batch_size": 16,
        "epochs": 1,
        "learning_rate": 0.001,
        "early_stopping": 3,
        "export_width": 128,
        "export_height": 128,
    },
    "dataset": [
        {
            "url": "https://ai.singtown.com/media/cat.0.jpg",
            "subset": "TRAIN",
            "classification": "cat",
        },
        {
            "url": "https://ai.singtown.com/media/cat.1.jpg",
            "subset": "VALID",
            "classification": "cat",
        },
        {
            "url": "https://ai.singtown.com/media/cat.2.jpg",
            "subset": "TEST",
            "classification": "cat",
        },
        {
            "url": "https://ai.singtown.com/media/dog.0.jpg",
            "subset": "TRAIN",
            "classification": "dog",
        },
        {
            "url": "https://ai.singtown.com/media/dog.1.jpg",
            "subset": "VALID",
            "classification": "dog",
        },
        {
            "url": "https://ai.singtown.com/media/dog.2.jpg",
            "subset": "TEST",
            "classification": "dog",
        },
    ],
}
with SingTownAiClient(mock=True) as client:
    pass  # Insert your code here
  • Set mock_data, Will mock demo task and dataset, this is useful for debugging.

Uploading Metrics

metrics = [
    {"epoch": 0, "accuracy": 0.8, "loss": 0.2},
    {"epoch": 1, "accuracy": 0.9, "loss": 0.1},
]
with SingTownAiClient() as client:
    client.upload_metrics(metrics)
  • The field names in metrics are not restricted, and they will appear on the Metrics page in SingTown AI.

Watching metrics.csv

with SingTownAiClient(metrics_file="metrics.csv") as client:
    pass  # Insert your code here
  • Every 3 seconds, the SDK will parse the metrics.csv and upload data.

Posting Logs

with SingTownAiClient() as client:
    import time
    for i in range(100):
        client.log(f"epoch: {i}")
        time.sleep(0.1)
  • This will upload log strings, posting them every 3 seconds.

Uploading Result Files

with SingTownAiClient() as client:
    client.upload_results_zip("your.zip")
  • This method uploads a .zip result file.

Run Subprocess Command

with SingTownAiClient() as client:
    client.run_subprocess("echo hello world!")
    client.run_subprocess("python3 train.py", ignore_stdout=True)
  • This method will run subprocess and log stdout and stderr.
  • If ignore_stdout=True , will not log stdout.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

singtown_ai-1.5.0.tar.gz (485.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

singtown_ai-1.5.0-py3-none-any.whl (490.7 kB view details)

Uploaded Python 3

File details

Details for the file singtown_ai-1.5.0.tar.gz.

File metadata

  • Download URL: singtown_ai-1.5.0.tar.gz
  • Upload date:
  • Size: 485.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for singtown_ai-1.5.0.tar.gz
Algorithm Hash digest
SHA256 7173284baccddcc9390409a93d8df7f1badb5ae20e574508b9c8782a18c2c219
MD5 a4c797921d0e8f552dea67f6dcdafcfb
BLAKE2b-256 1e212e6772cfd67034fe8a159d5c3c7725087d28204b460c5ad73684ca0c487f

See more details on using hashes here.

File details

Details for the file singtown_ai-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: singtown_ai-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 490.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for singtown_ai-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a54ae05bfc86e8b398cbc5ce2db025fb88b9a1b2ee93856154ae5baa09184b6d
MD5 2c3a43aa29b79c55a4c980d23b28f202
BLAKE2b-256 6f14969ffe8d0f771917f398ac8d2c1ae895af0c4ebf1e27794256af6a347e54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page