runapi-topaz 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ """Topaz client for RunAPI."""
2
+
3
+ from runapi.core import (
4
+ AuthenticationError,
5
+ InsufficientCreditsError,
6
+ NotFoundError,
7
+ RateLimitError,
8
+ TaskFailedError,
9
+ TaskTimeoutError,
10
+ ValidationError,
11
+ )
12
+
13
+ from .client import TopazClient
14
+
15
+ __all__ = [
16
+ "TopazClient",
17
+ "AuthenticationError",
18
+ "RateLimitError",
19
+ "InsufficientCreditsError",
20
+ "NotFoundError",
21
+ "ValidationError",
22
+ "TaskFailedError",
23
+ "TaskTimeoutError",
24
+ ]
runapi/topaz/client.py ADDED
@@ -0,0 +1,31 @@
1
+ """Topaz client."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import ClientOptions, HttpClient, resolve_api_key
8
+
9
+ from .resources.upscale_image import UpscaleImage
10
+ from .resources.upscale_video import UpscaleVideo
11
+
12
+
13
+ class TopazClient:
14
+ """Topaz image and video upscale client.
15
+
16
+ Example::
17
+
18
+ client = TopazClient(api_key="sk-...")
19
+ result = client.upscale_image.run(
20
+ model="topaz-upscale-image",
21
+ source_image_url="https://example.com/in.jpg",
22
+ upscale_factor=4,
23
+ )
24
+ """
25
+
26
+ def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
27
+ resolved_api_key = resolve_api_key(api_key)
28
+ client_options = ClientOptions(api_key=resolved_api_key, **options)
29
+ http = client_options.http_client or HttpClient(client_options)
30
+ self.upscale_image = UpscaleImage(http)
31
+ self.upscale_video = UpscaleVideo(http)
@@ -0,0 +1,31 @@
1
+ CONTRACT = {
2
+ "upscale-image": {
3
+ "models": ["topaz-upscale-image"],
4
+ "fields_by_model": {
5
+ "topaz-upscale-image": {
6
+ "source_image_url": {
7
+ "required": True
8
+ },
9
+ "upscale_factor": {
10
+ "enum": [1, 2, 4, 8],
11
+ "required": True,
12
+ "type": "integer"
13
+ }
14
+ }
15
+ }
16
+ },
17
+ "upscale-video": {
18
+ "models": ["topaz-upscale-video"],
19
+ "fields_by_model": {
20
+ "topaz-upscale-video": {
21
+ "source_video_url": {
22
+ "required": True
23
+ },
24
+ "upscale_factor": {
25
+ "enum": [1, 2, 4],
26
+ "type": "integer"
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
runapi/topaz/py.typed ADDED
File without changes
@@ -0,0 +1,4 @@
1
+ from .upscale_image import UpscaleImage
2
+ from .upscale_video import UpscaleVideo
3
+
4
+ __all__ = ["UpscaleImage", "UpscaleVideo"]
@@ -0,0 +1,58 @@
1
+ """Topaz upscale-image resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from runapi.core import Resource
8
+
9
+ from ..contract_gen import CONTRACT
10
+ from ..types import (
11
+ CompletedUpscaleImageResponse,
12
+ UpscaleImageResponse,
13
+ )
14
+
15
+
16
+ class UpscaleImage(Resource):
17
+ """Upscale images with Topaz."""
18
+
19
+ ENDPOINT = "/api/v1/topaz/upscale_image"
20
+
21
+ RESPONSE_CLASS = UpscaleImageResponse
22
+ COMPLETED_RESPONSE_CLASS = CompletedUpscaleImageResponse
23
+
24
+ def run(self, **params: Any) -> Any:
25
+ """Upscale an image and poll until it completes.
26
+
27
+ Args:
28
+ **params: image upscale parameters (model, ...).
29
+
30
+ Returns:
31
+ The completed (narrowed) image upscale response.
32
+ """
33
+ task = self.create(**params)
34
+ return self._poll_until_complete(lambda: self.get(task.id))
35
+
36
+ def create(self, **params: Any) -> Any:
37
+ """Create an image upscale task and return immediately with an id.
38
+
39
+ Args:
40
+ **params: image upscale parameters (model, ...).
41
+
42
+ Returns:
43
+ The task creation result with an id.
44
+ """
45
+ compacted = self._compact_params(params)
46
+ self._validate_contract(CONTRACT["upscale-image"], compacted)
47
+ return self._request("post", self.ENDPOINT, body=compacted)
48
+
49
+ def get(self, id: str) -> Any:
50
+ """Fetch the current status of an image upscale task.
51
+
52
+ Args:
53
+ id: The task id returned by ``create``.
54
+
55
+ Returns:
56
+ The current task status.
57
+ """
58
+ return self._request("get", f"{self.ENDPOINT}/{id}")
@@ -0,0 +1,58 @@
1
+ """Topaz upscale-video resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from runapi.core import Resource
8
+
9
+ from ..contract_gen import CONTRACT
10
+ from ..types import (
11
+ CompletedUpscaleVideoResponse,
12
+ UpscaleVideoResponse,
13
+ )
14
+
15
+
16
+ class UpscaleVideo(Resource):
17
+ """Upscale videos with Topaz."""
18
+
19
+ ENDPOINT = "/api/v1/topaz/upscale_video"
20
+
21
+ RESPONSE_CLASS = UpscaleVideoResponse
22
+ COMPLETED_RESPONSE_CLASS = CompletedUpscaleVideoResponse
23
+
24
+ def run(self, **params: Any) -> Any:
25
+ """Upscale a video and poll until it completes.
26
+
27
+ Args:
28
+ **params: video upscale parameters (model, ...).
29
+
30
+ Returns:
31
+ The completed (narrowed) video upscale response.
32
+ """
33
+ task = self.create(**params)
34
+ return self._poll_until_complete(lambda: self.get(task.id))
35
+
36
+ def create(self, **params: Any) -> Any:
37
+ """Create a video upscale task and return immediately with an id.
38
+
39
+ Args:
40
+ **params: video upscale parameters (model, ...).
41
+
42
+ Returns:
43
+ The task creation result with an id.
44
+ """
45
+ compacted = self._compact_params(params)
46
+ self._validate_contract(CONTRACT["upscale-video"], compacted)
47
+ return self._request("post", self.ENDPOINT, body=compacted)
48
+
49
+ def get(self, id: str) -> Any:
50
+ """Fetch the current status of a video upscale task.
51
+
52
+ Args:
53
+ id: The task id returned by ``create``.
54
+
55
+ Returns:
56
+ The current task status.
57
+ """
58
+ return self._request("get", f"{self.ENDPOINT}/{id}")
runapi/topaz/types.py ADDED
@@ -0,0 +1,43 @@
1
+ """Topaz response models."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from runapi.core import BaseModel, TaskResponse, optional, required
6
+
7
+
8
+ class Image(BaseModel):
9
+ url = optional(str)
10
+
11
+
12
+ class Video(BaseModel):
13
+ url = optional(str)
14
+
15
+
16
+ class UpscaleImageResponse(TaskResponse):
17
+ """Topaz image upscale task status response."""
18
+
19
+ id = required(str)
20
+ status = optional(str, enum=lambda: TaskResponse.Status.ALL)
21
+ images = optional([lambda: Image])
22
+ error = optional(str)
23
+
24
+
25
+ class UpscaleVideoResponse(TaskResponse):
26
+ """Topaz video upscale task status response."""
27
+
28
+ id = required(str)
29
+ status = optional(str, enum=lambda: TaskResponse.Status.ALL)
30
+ videos = optional([lambda: Video])
31
+ error = optional(str)
32
+
33
+
34
+ class CompletedUpscaleImageResponse(UpscaleImageResponse):
35
+ """Narrowed response from ``run()`` once polling observes completion."""
36
+
37
+ images = required([lambda: Image])
38
+
39
+
40
+ class CompletedUpscaleVideoResponse(UpscaleVideoResponse):
41
+ """Narrowed response from ``run()`` once polling observes completion."""
42
+
43
+ videos = required([lambda: Video])
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: runapi-topaz
3
+ Version: 0.1.0
4
+ Summary: Topaz image and video upscale client for RunAPI
5
+ Project-URL: Homepage, https://runapi.ai/models/topaz
6
+ Project-URL: Documentation, https://runapi.ai/docs#sdk-topaz
7
+ Author-email: RunAPI <contact@runapi.ai>
8
+ License-Expression: Apache-2.0
9
+ Keywords: ai,runapi,sdk,topaz,upscale-image,upscale-video
10
+ Requires-Python: >=3.9
11
+ Requires-Dist: runapi-core
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Topaz Python SDK for RunAPI
15
+
16
+ The Topaz Python SDK is the language-specific package for Topaz on RunAPI. Use it
17
+ for image upscale and video upscale flows when your application needs JSON request
18
+ bodies, task status lookup, and consistent RunAPI errors in Python.
19
+
20
+ For model details, use https://runapi.ai/models/topaz; for API reference, use
21
+ https://runapi.ai/docs#topaz; for SDK docs, use https://runapi.ai/docs#sdk-topaz.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install runapi-topaz
27
+ ```
28
+
29
+ ## Quick start
30
+
31
+ ```python
32
+ from runapi.topaz import TopazClient
33
+
34
+ client = TopazClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
35
+
36
+ task = client.upscale_image.create(
37
+ model="topaz-upscale-image",
38
+ source_image_url="https://example.com/in.jpg",
39
+ upscale_factor=4,
40
+ )
41
+ status = client.upscale_image.get(task.id)
42
+
43
+ video = client.upscale_video.create(
44
+ model="topaz-upscale-video",
45
+ source_video_url="https://example.com/in.mp4",
46
+ upscale_factor=2,
47
+ )
48
+ ```
49
+
50
+ Use `create` to submit a task and return quickly, `get` to fetch the latest task
51
+ state, and `run` to create and poll until completion:
52
+
53
+ ```python
54
+ result = client.upscale_image.run(
55
+ model="topaz-upscale-image",
56
+ source_image_url="https://example.com/in.jpg",
57
+ upscale_factor=4,
58
+ )
59
+ print(result.images[0].url)
60
+ ```
61
+
62
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a
63
+ worker is not held open.
64
+
65
+ RunAPI-generated file URLs are temporary. Download and store generated images and
66
+ videos in your own durable storage within 7 days; do not treat returned URLs as
67
+ long-term assets.
68
+
69
+ ## Language notes
70
+
71
+ Pass parameters as keyword arguments and catch the `runapi.topaz` error classes
72
+ when building upscaling jobs or scripts. The available resources are
73
+ `upscale_image` and `upscale_video`. Keep `RUNAPI_API_KEY` in the environment or
74
+ your secret manager; never commit API keys or callback secrets.
75
+
76
+ ## Links
77
+
78
+ - Model page: https://runapi.ai/models/topaz
79
+ - SDK docs: https://runapi.ai/docs#sdk-topaz
80
+ - Product docs: https://runapi.ai/docs#topaz
81
+ - Pricing and rate limits: https://runapi.ai/models/topaz
82
+ - Full catalog: https://runapi.ai/models
83
+
84
+ ## License
85
+
86
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,11 @@
1
+ runapi/topaz/__init__.py,sha256=8f27JnhHBgxeOA2nJQL8dohGd3cg-xjzI1phU2K5_nI,457
2
+ runapi/topaz/client.py,sha256=8owDlzgRQkZ7MwK_2MpgIQdWkbfbIfk5PXTZs7nHZqA,955
3
+ runapi/topaz/contract_gen.py,sha256=n_NPJVzHB8P6B9ioncE1QOIBqh_QFJzx6HCIBWG4Kcs,831
4
+ runapi/topaz/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ runapi/topaz/types.py,sha256=O_-QKRffiJJFN6p_fNgbqHI-tEJk_wk1PUui8yWaFB4,1090
6
+ runapi/topaz/resources/__init__.py,sha256=0ALsFeXvjqJCaqpTFNWGdDHcA944GGEIVMTJ-0TK50M,124
7
+ runapi/topaz/resources/upscale_image.py,sha256=kH-wll7ySJMKy1_C7cxvdP9M4Ocg1Eo9tHyk1BVumVc,1597
8
+ runapi/topaz/resources/upscale_video.py,sha256=XLjHg6-GZMLdSopkQdqi6duQ-G5EKo03_X4UZADr4IM,1594
9
+ runapi_topaz-0.1.0.dist-info/METADATA,sha256=LsWKYnPZUBHq0_g3nTwmTL0KHhwP9DhNFJuAR1YPeZw,2631
10
+ runapi_topaz-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
11
+ runapi_topaz-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any