runware 0.1.2__tar.gz

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.
runware-0.1.2/LICENSE ADDED
File without changes
runware-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.1
2
+ Name: runware
3
+ Version: 0.1.2
4
+ Summary: The Python Runware SDK is used to run image inference with the Runware API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.
5
+ Home-page: https://github.com/runware/sdk-python
6
+ Author: Runware Inc.
7
+ Author-email: python.sdk@runware.ai
8
+ License: MIT
9
+ Project-URL: Documentation, https://docs.runware.ai/
10
+ Project-URL: Changes, https://github.com/runware/sdk-python/releases
11
+ Project-URL: Code, https://github.com/runware/sdk-python
12
+ Project-URL: Issue tracker, https://github.com/runware/sdk-python/issues
13
+ Keywords: Runware,stable diffusion,text to image,image to text
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: aiofiles==23.2.1
26
+ Requires-Dist: python-dotenv==1.0.1
27
+ Requires-Dist: websockets==12.0
28
+
29
+ # Python Runware SDK
30
+
31
+ The Python Runware SDK is used to run image inference with the Runware API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.
32
+
33
+ ## Get API Access
34
+
35
+ To use the Python Runware SDK, you need to obtain an API key. Follow these steps to get API access:
36
+
37
+ 1. [Create a free account](https://my.runware.ai/) with [Runware](https://runware.ai/).
38
+ 2. Once you have created an account, you will receive an API key and trial credits.
39
+
40
+ **Important**: Please keep your API key private and do not share it with anyone. Treat it as a sensitive credential.
41
+
42
+ ## Documentation
43
+
44
+ For detailed documentation and API reference, please visit the [Runware Documentation](https://docs.runware.ai/) or refer to the [docs](docs) folder in the repository. The documentation provides comprehensive information about the available classes, methods, and parameters, along with code examples to help you get started with the Runware SDK Python.
45
+
46
+ ## Installation
47
+
48
+ To install the Python Runware SDK, use the following command:
49
+
50
+ ```bash
51
+ pip install runware
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ Before using the Python Runware SDK, make sure to set your Runware API key in the environment variable `RUNWARE_API_KEY`. You can do this by creating a `.env` file in your project root and adding the following line:
57
+
58
+ ```bash
59
+ RUNWARE_API_KEY = "your_api_key_here"
60
+ ```
61
+
62
+ ### Generating Images
63
+
64
+ To generate images using the Runware API, you can use the `requestImages` method of the `Runware` class. Here's an example:
65
+
66
+ ```python
67
+ from runware import Runware, IRequestImage
68
+
69
+ async def main() -> None:
70
+ runware = Runware(api_key=RUNWARE_API_KEY)
71
+ await runware.connect()
72
+
73
+ request_image = IRequestImage(
74
+ positive_prompt="A beautiful sunset over the mountains",
75
+ image_size=1,
76
+ model_id=13,
77
+ number_of_images=5,
78
+ negative_prompt="cloudy, rainy",
79
+ use_cache=False,
80
+ )
81
+
82
+ images = await runware.requestImages(requestImage=request_image)
83
+ for image in images:
84
+ print(f"Image URL: {image.imageSrc}")
85
+ ```
86
+
87
+ ### Enhancing Prompts
88
+
89
+ To enhance prompts using the Runware API, you can use the `enhancePrompt` method of the `Runware` class. Here's an example:
90
+
91
+ ```python
92
+ from runware import Runware, IPromptEnhancer
93
+
94
+ async def main() -> None:
95
+ runware = Runware(api_key=RUNWARE_API_KEY)
96
+ await runware.connect()
97
+
98
+ prompt = "A beautiful sunset over the mountains"
99
+ prompt_enhancer = IPromptEnhancer(
100
+ prompt=prompt,
101
+ prompt_versions=3,
102
+ )
103
+
104
+ enhanced_prompts = await runware.enhancePrompt(promptEnhancer=prompt_enhancer)
105
+ for enhanced_prompt in enhanced_prompts:
106
+ print(enhanced_prompt.text)
107
+ ```
108
+
109
+ ### Removing Image Background
110
+
111
+ To remove the background from an image using the Runware API, you can use the `removeImageBackground` method of the `Runware` class. Here's an example:
112
+
113
+ ```python
114
+ from runware import Runware, IRemoveImageBackground
115
+
116
+ async def main() -> None:
117
+ runware = Runware(api_key=RUNWARE_API_KEY)
118
+ await runware.connect()
119
+
120
+ image_path = "image.jpg"
121
+ remove_image_background_payload = IRemoveImageBackground(image_initiator=image_path)
122
+
123
+ processed_images = await runware.removeImageBackground(
124
+ removeImageBackgroundPayload=remove_image_background_payload
125
+ )
126
+ for image in processed_images:
127
+ print(image.imageSrc)
128
+ ```
129
+
130
+ ### Image-to-Text Conversion
131
+
132
+ To convert an image to text using the Runware API, you can use the `requestImageToText` method of the `Runware` class. Here's an example:
133
+
134
+ ```python
135
+ from runware import Runware, IRequestImageToText
136
+
137
+ async def main() -> None:
138
+ runware = Runware(api_key=RUNWARE_API_KEY)
139
+ await runware.connect()
140
+
141
+ image_path = "image.jpg"
142
+ request_image_to_text_payload = IRequestImageToText(image_initiator=image_path)
143
+
144
+ image_to_text = await runware.requestImageToText(
145
+ requestImageToText=request_image_to_text_payload
146
+ )
147
+ print(image_to_text.text)
148
+ ```
149
+
150
+ ### Upscaling Images
151
+
152
+ To upscale an image using the Runware API, you can use the `upscaleGan` method of the `Runware` class. Here's an example:
153
+
154
+ ```python
155
+ from runware import Runware, IUpscaleGan
156
+
157
+ async def main() -> None:
158
+ runware = Runware(api_key=RUNWARE_API_KEY)
159
+ await runware.connect()
160
+
161
+ image_path = "image.jpg"
162
+ upscale_factor = 4
163
+
164
+ upscale_gan_payload = IUpscaleGan(
165
+ image_initiator=image_path, upscale_factor=upscale_factor
166
+ )
167
+ upscaled_images = await runware.upscaleGan(upscaleGanPayload=upscale_gan_payload)
168
+ for image in upscaled_images:
169
+ print(image.imageSrc)
170
+ ```
171
+
172
+ For more detailed usage and additional examples, please refer to the examples directory.
@@ -0,0 +1,144 @@
1
+ # Python Runware SDK
2
+
3
+ The Python Runware SDK is used to run image inference with the Runware API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.
4
+
5
+ ## Get API Access
6
+
7
+ To use the Python Runware SDK, you need to obtain an API key. Follow these steps to get API access:
8
+
9
+ 1. [Create a free account](https://my.runware.ai/) with [Runware](https://runware.ai/).
10
+ 2. Once you have created an account, you will receive an API key and trial credits.
11
+
12
+ **Important**: Please keep your API key private and do not share it with anyone. Treat it as a sensitive credential.
13
+
14
+ ## Documentation
15
+
16
+ For detailed documentation and API reference, please visit the [Runware Documentation](https://docs.runware.ai/) or refer to the [docs](docs) folder in the repository. The documentation provides comprehensive information about the available classes, methods, and parameters, along with code examples to help you get started with the Runware SDK Python.
17
+
18
+ ## Installation
19
+
20
+ To install the Python Runware SDK, use the following command:
21
+
22
+ ```bash
23
+ pip install runware
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Before using the Python Runware SDK, make sure to set your Runware API key in the environment variable `RUNWARE_API_KEY`. You can do this by creating a `.env` file in your project root and adding the following line:
29
+
30
+ ```bash
31
+ RUNWARE_API_KEY = "your_api_key_here"
32
+ ```
33
+
34
+ ### Generating Images
35
+
36
+ To generate images using the Runware API, you can use the `requestImages` method of the `Runware` class. Here's an example:
37
+
38
+ ```python
39
+ from runware import Runware, IRequestImage
40
+
41
+ async def main() -> None:
42
+ runware = Runware(api_key=RUNWARE_API_KEY)
43
+ await runware.connect()
44
+
45
+ request_image = IRequestImage(
46
+ positive_prompt="A beautiful sunset over the mountains",
47
+ image_size=1,
48
+ model_id=13,
49
+ number_of_images=5,
50
+ negative_prompt="cloudy, rainy",
51
+ use_cache=False,
52
+ )
53
+
54
+ images = await runware.requestImages(requestImage=request_image)
55
+ for image in images:
56
+ print(f"Image URL: {image.imageSrc}")
57
+ ```
58
+
59
+ ### Enhancing Prompts
60
+
61
+ To enhance prompts using the Runware API, you can use the `enhancePrompt` method of the `Runware` class. Here's an example:
62
+
63
+ ```python
64
+ from runware import Runware, IPromptEnhancer
65
+
66
+ async def main() -> None:
67
+ runware = Runware(api_key=RUNWARE_API_KEY)
68
+ await runware.connect()
69
+
70
+ prompt = "A beautiful sunset over the mountains"
71
+ prompt_enhancer = IPromptEnhancer(
72
+ prompt=prompt,
73
+ prompt_versions=3,
74
+ )
75
+
76
+ enhanced_prompts = await runware.enhancePrompt(promptEnhancer=prompt_enhancer)
77
+ for enhanced_prompt in enhanced_prompts:
78
+ print(enhanced_prompt.text)
79
+ ```
80
+
81
+ ### Removing Image Background
82
+
83
+ To remove the background from an image using the Runware API, you can use the `removeImageBackground` method of the `Runware` class. Here's an example:
84
+
85
+ ```python
86
+ from runware import Runware, IRemoveImageBackground
87
+
88
+ async def main() -> None:
89
+ runware = Runware(api_key=RUNWARE_API_KEY)
90
+ await runware.connect()
91
+
92
+ image_path = "image.jpg"
93
+ remove_image_background_payload = IRemoveImageBackground(image_initiator=image_path)
94
+
95
+ processed_images = await runware.removeImageBackground(
96
+ removeImageBackgroundPayload=remove_image_background_payload
97
+ )
98
+ for image in processed_images:
99
+ print(image.imageSrc)
100
+ ```
101
+
102
+ ### Image-to-Text Conversion
103
+
104
+ To convert an image to text using the Runware API, you can use the `requestImageToText` method of the `Runware` class. Here's an example:
105
+
106
+ ```python
107
+ from runware import Runware, IRequestImageToText
108
+
109
+ async def main() -> None:
110
+ runware = Runware(api_key=RUNWARE_API_KEY)
111
+ await runware.connect()
112
+
113
+ image_path = "image.jpg"
114
+ request_image_to_text_payload = IRequestImageToText(image_initiator=image_path)
115
+
116
+ image_to_text = await runware.requestImageToText(
117
+ requestImageToText=request_image_to_text_payload
118
+ )
119
+ print(image_to_text.text)
120
+ ```
121
+
122
+ ### Upscaling Images
123
+
124
+ To upscale an image using the Runware API, you can use the `upscaleGan` method of the `Runware` class. Here's an example:
125
+
126
+ ```python
127
+ from runware import Runware, IUpscaleGan
128
+
129
+ async def main() -> None:
130
+ runware = Runware(api_key=RUNWARE_API_KEY)
131
+ await runware.connect()
132
+
133
+ image_path = "image.jpg"
134
+ upscale_factor = 4
135
+
136
+ upscale_gan_payload = IUpscaleGan(
137
+ image_initiator=image_path, upscale_factor=upscale_factor
138
+ )
139
+ upscaled_images = await runware.upscaleGan(upscaleGanPayload=upscale_gan_payload)
140
+ for image in upscaled_images:
141
+ print(image.imageSrc)
142
+ ```
143
+
144
+ For more detailed usage and additional examples, please refer to the examples directory.
@@ -0,0 +1,10 @@
1
+ from .server import RunwareServer as Runware
2
+ from .types import IRemoveImageBackground
3
+ from .types import *
4
+ from .utils import *
5
+ from .base import *
6
+ from .logging_config import *
7
+ from .async_retry import *
8
+
9
+ __all__ = ["Runware", "IRemoveImageBackground"]
10
+ __version__ = "0.1.0"
@@ -0,0 +1,96 @@
1
+ import asyncio
2
+
3
+
4
+ async def asyncRetry(apiCall, options=None):
5
+ """
6
+ Retry an asynchronous API call multiple times with configurable options.
7
+
8
+ :param apiCall: The asynchronous function to be retried.
9
+ :param options: An optional dictionary that allows you to configure the retry behavior.
10
+ It has the following properties:
11
+ - maxRetries: The maximum number of retries before giving up (default is 1).
12
+ - delayInSeconds: The delay in seconds between each retry attempt (default is 1).
13
+ - callback: A function that will be called after each failed attempt.
14
+ :return: The result of the successful API call.
15
+
16
+ This function retries an asynchronous API call multiple times with configurable options.
17
+ It attempts to execute the `apiCall` and returns the result if successful. If the `apiCall`
18
+ raises an exception, it calls the `callback` function (if provided), introduces a delay
19
+ before the next retry attempt, and continues retrying until the maximum number of retries
20
+ is reached. If all retry attempts are exhausted and the `apiCall` still fails, it raises
21
+ the last encountered exception.
22
+
23
+ Example:
24
+ async def myApiCall():
25
+ # API call logic here
26
+ ...
27
+
28
+ result = await asyncRetry(myApiCall, options={
29
+ 'maxRetries': 3,
30
+ 'delayInSeconds': 1,
31
+ 'callback': lambda: print('Retry attempt failed')
32
+ })
33
+ print(result)
34
+ """
35
+ if options is None:
36
+ options = {}
37
+ delayInSeconds = options.get("delayInSeconds", 1)
38
+ callback = options.get("callback")
39
+ maxRetries = options.get("maxRetries", 1)
40
+
41
+ for attempt in range(maxRetries):
42
+ try:
43
+ return await apiCall()
44
+ except Exception as error:
45
+ if callback:
46
+ callback()
47
+ if attempt < maxRetries - 1:
48
+ await asyncio.sleep(delayInSeconds)
49
+ else:
50
+ raise error
51
+
52
+
53
+ async def asyncRetryGather(apiCalls, options=None):
54
+ """
55
+ Retry multiple asynchronous API calls concurrently with configurable options.
56
+
57
+ :param apiCalls: A list of asynchronous functions to be retried.
58
+ :param options: An optional dictionary that allows you to configure the retry behavior.
59
+ It has the following properties:
60
+ - maxRetries: The maximum number of retries before giving up (default is 1).
61
+ - delayInSeconds: The delay in seconds between each retry attempt (default is 1).
62
+ - callback: A function that will be called after each failed attempt.
63
+ :return: A list of results from the successful API calls.
64
+
65
+ This function retries multiple asynchronous API calls concurrently with configurable options.
66
+ It creates tasks for each `apiCall` and executes them concurrently using `asyncio.gather()`.
67
+ Each task represents the execution of `asyncRetry` for a single `apiCall`. The results of
68
+ each successful API call are returned as a list in the same order as the input `apiCalls`.
69
+
70
+ Example:
71
+ async def myApiCall1():
72
+ # API call logic here
73
+ ...
74
+
75
+ async def myApiCall2():
76
+ # API call logic here
77
+ ...
78
+
79
+ results = await asyncRetryGather([myApiCall1, myApiCall2], options={
80
+ 'maxRetries': 3,
81
+ 'delayInSeconds': 1,
82
+ 'callback': lambda: print('Retry attempt failed')
83
+ })
84
+ print(results)
85
+ """
86
+ if options is None:
87
+ options = {}
88
+ delayInSeconds = options.get("delayInSeconds", 1)
89
+ callback = options.get("callback")
90
+ maxRetries = options.get("maxRetries", 1)
91
+
92
+ tasks = []
93
+ for apiCall in apiCalls:
94
+ task = asyncio.create_task(asyncRetry(apiCall, options))
95
+ tasks.append(task)
96
+ return await asyncio.gather(*tasks)