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:

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

Basic Usage

import time
from singtown_ai import SingTownAiClient
client = SingTownAiClient()
print(client.task)
client.export_class_folder(export_path) # or client.export_yolo(export_path)

metrics = []
for i in range(10):
    print("Train:", i)
    metrics.append({"epoch": i, "accuracy": i * 10})
    client.update_metrics(metrics)
    time.sleep(1)

client.upload_results_zip(uploadfile)

Update Metrics

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

Watching metrics.csv

from singtown_ai import SingTownAIClient, file_watcher

client = SingTownAiClient()

@file_watcher("path/to/metrics.csv", interval=3)
def file_on_change(content: str):
    import csv
    from io import StringIO

    metrics = list(csv.DictReader(StringIO(content)))
    if not metrics:
        return
    client.update_metrics(metrics)
  • Every 1 seconds, the SDK will parse the metrics.csv and upload metrics.

Logging

client = SingTownAiClient()
client.log("line")

Logging sys.stdout and stderror

from singtown_ai import SingTownAiClient, stdout_watcher

client = SingTownAiClient()

@stdout_watcher(interval=1)
def on_stdout_write(content: str):
    client.log(content, end="")
  • Every 1 seconds, the SDK will upload messages to logging.

Uploading Result Files

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

Mock

  • mock_task.json
{
        "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,
}
  • mock_dataset.json
[
  {
    "url": "https://github.com/singtown-ai/singtown-ai-datasets/raw/main/images/cat.0.jpg",
    "subset": "TRAIN",
    "classification": "cat"
  },
  {
    "url": "https://github.com/singtown-ai/singtown-ai-datasets/raw/main/images/cat.1.jpg",
    "subset": "VALID",
    "classification": "cat"
  },
  {
    "url": "https://github.com/singtown-ai/singtown-ai-datasets/raw/main/images/cat.2.jpg",
    "subset": "TEST",
    "classification": "cat"
  },
  {
    "url": "https://github.com/singtown-ai/singtown-ai-datasets/raw/main/images/dog.0.jpg",
    "subset": "TRAIN",
    "classification": "dog"
  },
  {
    "url": "https://github.com/singtown-ai/singtown-ai-datasets/raw/main/images/dog.1.jpg",
    "subset": "VALID",
    "classification": "dog"
  },
  {
    "url": "https://github.com/singtown-ai/singtown-ai-datasets/raw/main/images/dog.2.jpg",
    "subset": "TEST",
    "classification": "dog"
  }
]

Environment Variables:

export SINGTOWN_AI_MOCK_TASK_URL="mock_task.json"
export SINGTOWN_AI_MOCK_DATASET_URL="mock_dataset.json"

Alternatively, set them directly in code:

client = SingTownAiClient(
    mock_task_url="mock_task.json",
    mock_dataset_url="mock_dataset.json",
)
  • Set mock_data, Will mock demo task and dataset, this is useful for debugging.

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.8.0.tar.gz (6.8 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.8.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: singtown_ai-1.8.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.7

File hashes

Hashes for singtown_ai-1.8.0.tar.gz
Algorithm Hash digest
SHA256 102a6a5c970f345c4de31c12a3173a34d708f88a0dc061bdf8d1523de8f3a996
MD5 5fac6785849d9c9d35ee26b75cac7ae7
BLAKE2b-256 cc683ae6e5a35245c4aa277661029bc4a50474ba2e3a46b8de88fadd9eb95306

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for singtown_ai-1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c7eb98872391e6da8b23a3468ee9dce7eb47f49261974a82f02fc51a7c22bea
MD5 dc36f9fb1ce8d3780b8c58aca94044aa
BLAKE2b-256 b7af009816b219a75e7b65483ef69ca2798c9e3d3adf8eec9e64785d5402e07c

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