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
hostis"https://ai.singtown.com". - SingTown AI Standalone (self-hosted): The
hostis 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)
Mock Usage
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",
},
],
}
client = SingTownAiClient(mock_data=mock_data)
- Set mock_data, Will mock demo task and dataset, this is useful for debugging.
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
metricsare 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.csvand 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
.zipresult file.
Project details
Release history Release notifications | RSS feed
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.6.1.tar.gz
(484.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
singtown_ai-1.6.1-py3-none-any.whl
(489.9 kB
view details)
File details
Details for the file singtown_ai-1.6.1.tar.gz.
File metadata
- Download URL: singtown_ai-1.6.1.tar.gz
- Upload date:
- Size: 484.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b27010602b6464d6f9c8eb43452438d4e476051d09cdac9ad7d9f3b9b5752168
|
|
| MD5 |
c57730e6f5abf7f646204f26b50bff2e
|
|
| BLAKE2b-256 |
e9aa4ccdca2fcfde35863f9d995cce3c007dbb690e98780139f15f47245e0169
|
File details
Details for the file singtown_ai-1.6.1-py3-none-any.whl.
File metadata
- Download URL: singtown_ai-1.6.1-py3-none-any.whl
- Upload date:
- Size: 489.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f2113d98ce8b13450476b4bc4825bb9e9351a3e8ead77d06190c5eecefefcb8
|
|
| MD5 |
fc35876f6abc63d2170515d56ffd4230
|
|
| BLAKE2b-256 |
b8057e8b3e4bf8fc6c0ac678afa25fba1a8dedd7d567c38238bb500bf987198f
|