runware 0.4.0__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.4.0/LICENSE +0 -0
- runware-0.4.0/PKG-INFO +353 -0
- runware-0.4.0/README.md +313 -0
- runware-0.4.0/runware/__init__.py +10 -0
- runware-0.4.0/runware/async_retry.py +96 -0
- runware-0.4.0/runware/base.py +1332 -0
- runware-0.4.0/runware/logging_config.py +29 -0
- runware-0.4.0/runware/server.py +311 -0
- runware-0.4.0/runware/types.py +749 -0
- runware-0.4.0/runware/utils.py +769 -0
- runware-0.4.0/runware.egg-info/PKG-INFO +353 -0
- runware-0.4.0/runware.egg-info/SOURCES.txt +20 -0
- runware-0.4.0/runware.egg-info/dependency_links.txt +1 -0
- runware-0.4.0/runware.egg-info/requires.txt +3 -0
- runware-0.4.0/runware.egg-info/top_level.txt +2 -0
- runware-0.4.0/setup.cfg +4 -0
- runware-0.4.0/setup.py +42 -0
- runware-0.4.0/tests/__init__.py +0 -0
- runware-0.4.0/tests/test_base.py +0 -0
- runware-0.4.0/tests/test_server.py +0 -0
- runware-0.4.0/tests/test_types.py +236 -0
- runware-0.4.0/tests/test_utils.py +297 -0
runware-0.4.0/LICENSE
ADDED
|
File without changes
|
runware-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: runware
|
|
3
|
+
Version: 0.4.0
|
|
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 images 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
|
+
Dynamic: author
|
|
29
|
+
Dynamic: author-email
|
|
30
|
+
Dynamic: classifier
|
|
31
|
+
Dynamic: description
|
|
32
|
+
Dynamic: description-content-type
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: keywords
|
|
35
|
+
Dynamic: license
|
|
36
|
+
Dynamic: project-url
|
|
37
|
+
Dynamic: requires-dist
|
|
38
|
+
Dynamic: requires-python
|
|
39
|
+
Dynamic: summary
|
|
40
|
+
|
|
41
|
+
# Python Runware SDK
|
|
42
|
+
|
|
43
|
+
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 images 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.
|
|
44
|
+
|
|
45
|
+
## Get API Access
|
|
46
|
+
|
|
47
|
+
To use the Python Runware SDK, you need to obtain an API key. Follow these steps to get API access:
|
|
48
|
+
|
|
49
|
+
1. [Create a free account](https://my.runware.ai/) with [Runware](https://runware.ai/).
|
|
50
|
+
2. Once you have created an account, you will receive an API key and trial credits.
|
|
51
|
+
|
|
52
|
+
**Important**: Please keep your API key private and do not share it with anyone. Treat it as a sensitive credential.
|
|
53
|
+
|
|
54
|
+
## Documentation
|
|
55
|
+
|
|
56
|
+
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.
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
To install the Python Runware SDK, use the following command:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install runware
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
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:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
RUNWARE_API_KEY = "your_api_key_here"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Generating Images
|
|
75
|
+
|
|
76
|
+
To generate images using the Runware API, you can use the `imageInference` method of the `Runware` class. Here's an example:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from runware import Runware, IImageInference
|
|
80
|
+
|
|
81
|
+
async def main() -> None:
|
|
82
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
83
|
+
await runware.connect()
|
|
84
|
+
|
|
85
|
+
request_image = IImageInference(
|
|
86
|
+
positivePrompt="a beautiful sunset over the mountains",
|
|
87
|
+
model="civitai:36520@76907",
|
|
88
|
+
numberResults=4,
|
|
89
|
+
negativePrompt="cloudy, rainy",
|
|
90
|
+
height=512,
|
|
91
|
+
width=512,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
images = await runware.imageInference(requestImage=request_image)
|
|
95
|
+
for image in images:
|
|
96
|
+
print(f"Image URL: {image.imageURL}")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Enhancing Prompts
|
|
100
|
+
|
|
101
|
+
To enhance prompts using the Runware API, you can use the `promptEnhance` method of the `Runware` class. Here's an example:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from runware import Runware, IPromptEnhance
|
|
105
|
+
|
|
106
|
+
async def main() -> None:
|
|
107
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
108
|
+
await runware.connect()
|
|
109
|
+
|
|
110
|
+
prompt = "A beautiful sunset over the mountains"
|
|
111
|
+
prompt_enhancer = IPromptEnhance(
|
|
112
|
+
prompt=prompt,
|
|
113
|
+
promptVersions=3,
|
|
114
|
+
promptMaxLength=64,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
enhanced_prompts = await runware.promptEnhance(promptEnhancer=prompt_enhancer)
|
|
118
|
+
for enhanced_prompt in enhanced_prompts:
|
|
119
|
+
print(enhanced_prompt.text)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Removing Image Background
|
|
123
|
+
|
|
124
|
+
To remove the background from an image using the Runware API, you can use the `imageBackgroundRemoval` method of the `Runware` class. Here's an example:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from runware import Runware, IImageBackgroundRemoval
|
|
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
|
+
remove_image_background_payload = IImageBackgroundRemoval(image_initiator=image_path)
|
|
135
|
+
|
|
136
|
+
processed_images = await runware.imageBackgroundRemoval(
|
|
137
|
+
removeImageBackgroundPayload=remove_image_background_payload
|
|
138
|
+
)
|
|
139
|
+
for image in processed_images:
|
|
140
|
+
print(image.imageURL)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Image-to-Text Conversion
|
|
144
|
+
|
|
145
|
+
To convert an image to text using the Runware API, you can use the `imageCaption` method of the `Runware` class. Here's an example:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from runware import Runware, IRequestImageToText
|
|
149
|
+
|
|
150
|
+
async def main() -> None:
|
|
151
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
152
|
+
await runware.connect()
|
|
153
|
+
|
|
154
|
+
image_path = "image.jpg"
|
|
155
|
+
request_image_to_text_payload = IImageCaption(image_initiator=image_path)
|
|
156
|
+
|
|
157
|
+
image_to_text = await runware.imageCaption(
|
|
158
|
+
requestImageToText=request_image_to_text_payload
|
|
159
|
+
)
|
|
160
|
+
print(image_to_text.text)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Upscaling Images
|
|
164
|
+
|
|
165
|
+
To upscale an image using the Runware API, you can use the `imageUpscale` method of the `Runware` class. Here's an example:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from runware import Runware, IImageUpscale
|
|
169
|
+
|
|
170
|
+
async def main() -> None:
|
|
171
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
172
|
+
await runware.connect()
|
|
173
|
+
|
|
174
|
+
image_path = "image.jpg"
|
|
175
|
+
upscale_factor = 4
|
|
176
|
+
|
|
177
|
+
upscale_gan_payload = IImageUpscale(
|
|
178
|
+
inputImage=image_path, upscaleFactor=upscale_factor
|
|
179
|
+
)
|
|
180
|
+
upscaled_images = await runware.imageUpscale(upscaleGanPayload=upscale_gan_payload)
|
|
181
|
+
for image in upscaled_images:
|
|
182
|
+
print(image.imageSrc)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Photo Maker
|
|
186
|
+
|
|
187
|
+
Use the `photoMaker` method of the `Runware` class. Here's an example:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from runware import Runware, IPhotoMaker
|
|
191
|
+
import uuid
|
|
192
|
+
|
|
193
|
+
async def main() -> None:
|
|
194
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
195
|
+
await runware.connect()
|
|
196
|
+
|
|
197
|
+
request_image = IPhotoMaker(
|
|
198
|
+
model="civitai:101055@128080",
|
|
199
|
+
positivePrompt="img of a beautiful lady in a forest",
|
|
200
|
+
steps=35,
|
|
201
|
+
numberResults=1,
|
|
202
|
+
height=512,
|
|
203
|
+
width=512,
|
|
204
|
+
style="No style",
|
|
205
|
+
strength=40,
|
|
206
|
+
outputFormat="WEBP",
|
|
207
|
+
includeCost=True,
|
|
208
|
+
taskUUID=str(uuid.uuid4()),
|
|
209
|
+
inputImages=[
|
|
210
|
+
"https://im.runware.ai/image/ws/0.5/ii/74723926-22f6-417c-befb-f2058fc88c13.webp",
|
|
211
|
+
"https://im.runware.ai/image/ws/0.5/ii/64acee31-100d-4aa1-a47e-6f8b432e7188.webp",
|
|
212
|
+
"https://im.runware.ai/image/ws/0.5/ii/1b39b0e0-6bf7-4c9a-8134-c0251b5ede01.webp",
|
|
213
|
+
"https://im.runware.ai/image/ws/0.5/ii/f4b4cec3-66d9-4c02-97c5-506b8813182a.webp"
|
|
214
|
+
],
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
photos = await runware.photoMaker(requestPhotoMaker=request_image)
|
|
219
|
+
for photo in photos:
|
|
220
|
+
print(f"Image URL: {photo.imageURL}")
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Generating Images with refiner
|
|
224
|
+
|
|
225
|
+
To generate images using the Runware API with refiner support, you can use the `imageInference` method of the `Runware` class. Here's an example:
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from runware import Runware, IImageInference, IRefiner
|
|
229
|
+
|
|
230
|
+
async def main() -> None:
|
|
231
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
232
|
+
await runware.connect()
|
|
233
|
+
|
|
234
|
+
refiner = IRefiner(
|
|
235
|
+
model="civitai:101055@128080",
|
|
236
|
+
startStep=a,
|
|
237
|
+
startStepPercentage=None,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
request_image = IImageInference(
|
|
241
|
+
positivePrompt="a beautiful sunset over the mountains",
|
|
242
|
+
model="civitai:36520@76907",
|
|
243
|
+
numberResults=4,
|
|
244
|
+
negativePrompt="cloudy, rainy",
|
|
245
|
+
height=512,
|
|
246
|
+
width=512,
|
|
247
|
+
refiner=refiner
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
images = await runware.imageInference(requestImage=request_image)
|
|
251
|
+
for image in images:
|
|
252
|
+
print(f"Image URL: {image.imageURL}")
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Model Upload
|
|
256
|
+
|
|
257
|
+
To upload model using the Runware API, you can use the `uploadModel` method of the `Runware` class. Here are examples:
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
from runware import Runware, IImageInference, IRefiner, IUploadModelCheckPoint
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
async def main() -> None:
|
|
264
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
265
|
+
await runware.connect()
|
|
266
|
+
|
|
267
|
+
payload = IUploadModelCheckPoint(
|
|
268
|
+
air='qatests:68487@08629',
|
|
269
|
+
name='yWO8IaKwez',
|
|
270
|
+
heroImageUrl='https://raw.githubusercontent.com/adilentiq/test-images/refs/heads/main/image.jpg',
|
|
271
|
+
downloadUrl='https://repo-controlnets-r2.runware.ai/controlnet-zoe-depth-sdxl-1.0.safetensors'
|
|
272
|
+
'/controlnet-zoe-depth-sdxl-1.0.safetensors.part-001-1',
|
|
273
|
+
uniqueIdentifier='aq2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1234',
|
|
274
|
+
version='1.0',
|
|
275
|
+
tags=['tag1', 'tag2', 'tag2'],
|
|
276
|
+
architecture='flux1d',
|
|
277
|
+
type='base',
|
|
278
|
+
defaultWeight=0.8,
|
|
279
|
+
format='safetensors',
|
|
280
|
+
positiveTriggerWords='my trigger word',
|
|
281
|
+
shortDescription='a model description',
|
|
282
|
+
private=False,
|
|
283
|
+
defaultScheduler='Default',
|
|
284
|
+
comment='some comments if you want to add for internal use',
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
uploaded = await runware.modelUpload(payload)
|
|
288
|
+
print(f"Response : {uploaded}")
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
from runware import Runware, IImageInference, IRefiner, IUploadModelLora
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
async def main() -> None:
|
|
296
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
297
|
+
await runware.connect()
|
|
298
|
+
|
|
299
|
+
payload = IUploadModelLora(
|
|
300
|
+
air='qatests:68487@08629',
|
|
301
|
+
name='yWO8IaKwez',
|
|
302
|
+
heroImageUrl='https://raw.githubusercontent.com/adilentiq/test-images/refs/heads/main/image.jpg',
|
|
303
|
+
downloadUrl='https://repo-controlnets-r2.runware.ai/controlnet-zoe-depth-sdxl-1.0.safetensors'
|
|
304
|
+
'/controlnet-zoe-depth-sdxl-1.0.safetensors.part-001-1',
|
|
305
|
+
uniqueIdentifier='aq2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1234',
|
|
306
|
+
version='1.0',
|
|
307
|
+
tags=['tag1', 'tag2', 'tag2'],
|
|
308
|
+
architecture='flux1d',
|
|
309
|
+
type='base',
|
|
310
|
+
defaultWeight=0.8,
|
|
311
|
+
format='safetensors',
|
|
312
|
+
positiveTriggerWords='my trigger word',
|
|
313
|
+
shortDescription='a model description',
|
|
314
|
+
private=False,
|
|
315
|
+
comment='some comments if you want to add for internal use',
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
uploaded = await runware.modelUpload(payload)
|
|
319
|
+
print(f"Response : {uploaded}")
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
```python
|
|
323
|
+
from runware import Runware, IImageInference, IRefiner, IUploadModelControlNet
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
async def main() -> None:
|
|
327
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
328
|
+
await runware.connect()
|
|
329
|
+
|
|
330
|
+
payload = IUploadModelControlNet(
|
|
331
|
+
air='qatests:68487@08629',
|
|
332
|
+
name='yWO8IaKwez',
|
|
333
|
+
heroImageUrl='https://raw.githubusercontent.com/adilentiq/test-images/refs/heads/main/image.jpg',
|
|
334
|
+
downloadUrl='https://repo-controlnets-r2.runware.ai/controlnet-zoe-depth-sdxl-1.0.safetensors'
|
|
335
|
+
'/controlnet-zoe-depth-sdxl-1.0.safetensors.part-001-1',
|
|
336
|
+
uniqueIdentifier='aq2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1234',
|
|
337
|
+
version='1.0',
|
|
338
|
+
tags=['tag1', 'tag2', 'tag2'],
|
|
339
|
+
architecture='flux1d',
|
|
340
|
+
type='base',
|
|
341
|
+
format='safetensors',
|
|
342
|
+
positiveTriggerWords='my trigger word',
|
|
343
|
+
shortDescription='a model description',
|
|
344
|
+
private=False,
|
|
345
|
+
comment='some comments if you want to add for internal use',
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
uploaded = await runware.modelUpload(payload)
|
|
350
|
+
print(f"Response : {uploaded}")
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
For more detailed usage and additional examples, please refer to the examples directory.
|
runware-0.4.0/README.md
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
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 images 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 `imageInference` method of the `Runware` class. Here's an example:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from runware import Runware, IImageInference
|
|
40
|
+
|
|
41
|
+
async def main() -> None:
|
|
42
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
43
|
+
await runware.connect()
|
|
44
|
+
|
|
45
|
+
request_image = IImageInference(
|
|
46
|
+
positivePrompt="a beautiful sunset over the mountains",
|
|
47
|
+
model="civitai:36520@76907",
|
|
48
|
+
numberResults=4,
|
|
49
|
+
negativePrompt="cloudy, rainy",
|
|
50
|
+
height=512,
|
|
51
|
+
width=512,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
images = await runware.imageInference(requestImage=request_image)
|
|
55
|
+
for image in images:
|
|
56
|
+
print(f"Image URL: {image.imageURL}")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Enhancing Prompts
|
|
60
|
+
|
|
61
|
+
To enhance prompts using the Runware API, you can use the `promptEnhance` method of the `Runware` class. Here's an example:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from runware import Runware, IPromptEnhance
|
|
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 = IPromptEnhance(
|
|
72
|
+
prompt=prompt,
|
|
73
|
+
promptVersions=3,
|
|
74
|
+
promptMaxLength=64,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
enhanced_prompts = await runware.promptEnhance(promptEnhancer=prompt_enhancer)
|
|
78
|
+
for enhanced_prompt in enhanced_prompts:
|
|
79
|
+
print(enhanced_prompt.text)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Removing Image Background
|
|
83
|
+
|
|
84
|
+
To remove the background from an image using the Runware API, you can use the `imageBackgroundRemoval` method of the `Runware` class. Here's an example:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from runware import Runware, IImageBackgroundRemoval
|
|
88
|
+
|
|
89
|
+
async def main() -> None:
|
|
90
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
91
|
+
await runware.connect()
|
|
92
|
+
|
|
93
|
+
image_path = "image.jpg"
|
|
94
|
+
remove_image_background_payload = IImageBackgroundRemoval(image_initiator=image_path)
|
|
95
|
+
|
|
96
|
+
processed_images = await runware.imageBackgroundRemoval(
|
|
97
|
+
removeImageBackgroundPayload=remove_image_background_payload
|
|
98
|
+
)
|
|
99
|
+
for image in processed_images:
|
|
100
|
+
print(image.imageURL)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Image-to-Text Conversion
|
|
104
|
+
|
|
105
|
+
To convert an image to text using the Runware API, you can use the `imageCaption` method of the `Runware` class. Here's an example:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from runware import Runware, IRequestImageToText
|
|
109
|
+
|
|
110
|
+
async def main() -> None:
|
|
111
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
112
|
+
await runware.connect()
|
|
113
|
+
|
|
114
|
+
image_path = "image.jpg"
|
|
115
|
+
request_image_to_text_payload = IImageCaption(image_initiator=image_path)
|
|
116
|
+
|
|
117
|
+
image_to_text = await runware.imageCaption(
|
|
118
|
+
requestImageToText=request_image_to_text_payload
|
|
119
|
+
)
|
|
120
|
+
print(image_to_text.text)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Upscaling Images
|
|
124
|
+
|
|
125
|
+
To upscale an image using the Runware API, you can use the `imageUpscale` method of the `Runware` class. Here's an example:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from runware import Runware, IImageUpscale
|
|
129
|
+
|
|
130
|
+
async def main() -> None:
|
|
131
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
132
|
+
await runware.connect()
|
|
133
|
+
|
|
134
|
+
image_path = "image.jpg"
|
|
135
|
+
upscale_factor = 4
|
|
136
|
+
|
|
137
|
+
upscale_gan_payload = IImageUpscale(
|
|
138
|
+
inputImage=image_path, upscaleFactor=upscale_factor
|
|
139
|
+
)
|
|
140
|
+
upscaled_images = await runware.imageUpscale(upscaleGanPayload=upscale_gan_payload)
|
|
141
|
+
for image in upscaled_images:
|
|
142
|
+
print(image.imageSrc)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Photo Maker
|
|
146
|
+
|
|
147
|
+
Use the `photoMaker` method of the `Runware` class. Here's an example:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from runware import Runware, IPhotoMaker
|
|
151
|
+
import uuid
|
|
152
|
+
|
|
153
|
+
async def main() -> None:
|
|
154
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
155
|
+
await runware.connect()
|
|
156
|
+
|
|
157
|
+
request_image = IPhotoMaker(
|
|
158
|
+
model="civitai:101055@128080",
|
|
159
|
+
positivePrompt="img of a beautiful lady in a forest",
|
|
160
|
+
steps=35,
|
|
161
|
+
numberResults=1,
|
|
162
|
+
height=512,
|
|
163
|
+
width=512,
|
|
164
|
+
style="No style",
|
|
165
|
+
strength=40,
|
|
166
|
+
outputFormat="WEBP",
|
|
167
|
+
includeCost=True,
|
|
168
|
+
taskUUID=str(uuid.uuid4()),
|
|
169
|
+
inputImages=[
|
|
170
|
+
"https://im.runware.ai/image/ws/0.5/ii/74723926-22f6-417c-befb-f2058fc88c13.webp",
|
|
171
|
+
"https://im.runware.ai/image/ws/0.5/ii/64acee31-100d-4aa1-a47e-6f8b432e7188.webp",
|
|
172
|
+
"https://im.runware.ai/image/ws/0.5/ii/1b39b0e0-6bf7-4c9a-8134-c0251b5ede01.webp",
|
|
173
|
+
"https://im.runware.ai/image/ws/0.5/ii/f4b4cec3-66d9-4c02-97c5-506b8813182a.webp"
|
|
174
|
+
],
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
photos = await runware.photoMaker(requestPhotoMaker=request_image)
|
|
179
|
+
for photo in photos:
|
|
180
|
+
print(f"Image URL: {photo.imageURL}")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Generating Images with refiner
|
|
184
|
+
|
|
185
|
+
To generate images using the Runware API with refiner support, you can use the `imageInference` method of the `Runware` class. Here's an example:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from runware import Runware, IImageInference, IRefiner
|
|
189
|
+
|
|
190
|
+
async def main() -> None:
|
|
191
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
192
|
+
await runware.connect()
|
|
193
|
+
|
|
194
|
+
refiner = IRefiner(
|
|
195
|
+
model="civitai:101055@128080",
|
|
196
|
+
startStep=a,
|
|
197
|
+
startStepPercentage=None,
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
request_image = IImageInference(
|
|
201
|
+
positivePrompt="a beautiful sunset over the mountains",
|
|
202
|
+
model="civitai:36520@76907",
|
|
203
|
+
numberResults=4,
|
|
204
|
+
negativePrompt="cloudy, rainy",
|
|
205
|
+
height=512,
|
|
206
|
+
width=512,
|
|
207
|
+
refiner=refiner
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
images = await runware.imageInference(requestImage=request_image)
|
|
211
|
+
for image in images:
|
|
212
|
+
print(f"Image URL: {image.imageURL}")
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Model Upload
|
|
216
|
+
|
|
217
|
+
To upload model using the Runware API, you can use the `uploadModel` method of the `Runware` class. Here are examples:
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
from runware import Runware, IImageInference, IRefiner, IUploadModelCheckPoint
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
async def main() -> None:
|
|
224
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
225
|
+
await runware.connect()
|
|
226
|
+
|
|
227
|
+
payload = IUploadModelCheckPoint(
|
|
228
|
+
air='qatests:68487@08629',
|
|
229
|
+
name='yWO8IaKwez',
|
|
230
|
+
heroImageUrl='https://raw.githubusercontent.com/adilentiq/test-images/refs/heads/main/image.jpg',
|
|
231
|
+
downloadUrl='https://repo-controlnets-r2.runware.ai/controlnet-zoe-depth-sdxl-1.0.safetensors'
|
|
232
|
+
'/controlnet-zoe-depth-sdxl-1.0.safetensors.part-001-1',
|
|
233
|
+
uniqueIdentifier='aq2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1234',
|
|
234
|
+
version='1.0',
|
|
235
|
+
tags=['tag1', 'tag2', 'tag2'],
|
|
236
|
+
architecture='flux1d',
|
|
237
|
+
type='base',
|
|
238
|
+
defaultWeight=0.8,
|
|
239
|
+
format='safetensors',
|
|
240
|
+
positiveTriggerWords='my trigger word',
|
|
241
|
+
shortDescription='a model description',
|
|
242
|
+
private=False,
|
|
243
|
+
defaultScheduler='Default',
|
|
244
|
+
comment='some comments if you want to add for internal use',
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
uploaded = await runware.modelUpload(payload)
|
|
248
|
+
print(f"Response : {uploaded}")
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from runware import Runware, IImageInference, IRefiner, IUploadModelLora
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
async def main() -> None:
|
|
256
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
257
|
+
await runware.connect()
|
|
258
|
+
|
|
259
|
+
payload = IUploadModelLora(
|
|
260
|
+
air='qatests:68487@08629',
|
|
261
|
+
name='yWO8IaKwez',
|
|
262
|
+
heroImageUrl='https://raw.githubusercontent.com/adilentiq/test-images/refs/heads/main/image.jpg',
|
|
263
|
+
downloadUrl='https://repo-controlnets-r2.runware.ai/controlnet-zoe-depth-sdxl-1.0.safetensors'
|
|
264
|
+
'/controlnet-zoe-depth-sdxl-1.0.safetensors.part-001-1',
|
|
265
|
+
uniqueIdentifier='aq2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1234',
|
|
266
|
+
version='1.0',
|
|
267
|
+
tags=['tag1', 'tag2', 'tag2'],
|
|
268
|
+
architecture='flux1d',
|
|
269
|
+
type='base',
|
|
270
|
+
defaultWeight=0.8,
|
|
271
|
+
format='safetensors',
|
|
272
|
+
positiveTriggerWords='my trigger word',
|
|
273
|
+
shortDescription='a model description',
|
|
274
|
+
private=False,
|
|
275
|
+
comment='some comments if you want to add for internal use',
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
uploaded = await runware.modelUpload(payload)
|
|
279
|
+
print(f"Response : {uploaded}")
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
from runware import Runware, IImageInference, IRefiner, IUploadModelControlNet
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
async def main() -> None:
|
|
287
|
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
|
288
|
+
await runware.connect()
|
|
289
|
+
|
|
290
|
+
payload = IUploadModelControlNet(
|
|
291
|
+
air='qatests:68487@08629',
|
|
292
|
+
name='yWO8IaKwez',
|
|
293
|
+
heroImageUrl='https://raw.githubusercontent.com/adilentiq/test-images/refs/heads/main/image.jpg',
|
|
294
|
+
downloadUrl='https://repo-controlnets-r2.runware.ai/controlnet-zoe-depth-sdxl-1.0.safetensors'
|
|
295
|
+
'/controlnet-zoe-depth-sdxl-1.0.safetensors.part-001-1',
|
|
296
|
+
uniqueIdentifier='aq2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1q2w3e4r5t6y7u8i9o0p1234',
|
|
297
|
+
version='1.0',
|
|
298
|
+
tags=['tag1', 'tag2', 'tag2'],
|
|
299
|
+
architecture='flux1d',
|
|
300
|
+
type='base',
|
|
301
|
+
format='safetensors',
|
|
302
|
+
positiveTriggerWords='my trigger word',
|
|
303
|
+
shortDescription='a model description',
|
|
304
|
+
private=False,
|
|
305
|
+
comment='some comments if you want to add for internal use',
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
uploaded = await runware.modelUpload(payload)
|
|
310
|
+
print(f"Response : {uploaded}")
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
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 IImageBackgroundRemoval
|
|
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", "IImageBackgroundRemoval"]
|
|
10
|
+
__version__ = "0.4.0"
|