-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Description
Problem Description
In the documentation, the input request parameters are all reported as dicts that will be parsed by the IImageInference class.
A typical input is as follows, as reported by the documentation:
{
"taskType": "imageInference",
"taskUUID": "6ba7b832-9dad-11d1-80b4-00c04fd430c8",
"model": "bfl:7@1",
"positivePrompt": "Create a realistic, high-quality image of a person using all provided reference images to preserve the same character identity."
"inputs": {
"referenceImages": [
"c64351d5-4c59-42f7-95e1-eace013eddab",
"d7e8f9a0-2b5c-4e7f-a1d3-9c8b7a6e5d4f",
"e8f9a0b1-3c6d-4e8f-b2e4-0d9e8f7c6b5a",
"f9a0b1c2-4d7e-5f9g-c3f5-1e0f9g8d7c6b",
"a1b2c3d4-5e6f-7g8h-d4f6-2f1g0h9i8h7g"
]
},
"width": 1280,
"height": 720
}When passing the inputs in this format, the server raises an error and produces the following stack trace:
Traceback (most recent call last):
File "/Users/rsortino/projects/glare-removal/sdk-python/repro_error.py", line 68, in <module>
asyncio.run(main())
File "/Users/rsortino/.local/share/uv/python/cpython-3.11.12-macos-aarch64-none/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Users/rsortino/.local/share/uv/python/cpython-3.11.12-macos-aarch64-none/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rsortino/.local/share/uv/python/cpython-3.11.12-macos-aarch64-none/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/rsortino/projects/glare-removal/sdk-python/repro_error.py", line 63, in main
images = await runware.imageInference(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rsortino/projects/glare-removal/sdk-python/runware/base.py", line 445, in imageInference
return await self._retry_with_reconnect(self._imageInference, requestImage)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rsortino/projects/glare-removal/sdk-python/runware/base.py", line 146, in _retry_with_reconnect
result = await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rsortino/projects/glare-removal/sdk-python/runware/base.py", line 567, in _imageInference
raise e
File "/Users/rsortino/projects/glare-removal/sdk-python/runware/base.py", line 538, in _imageInference
request_object = self._buildImageRequest(requestImage, prompt, control_net_data_dicts, instant_id_data, ip_adapters_data, ace_plus_plus_data, pulid_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rsortino/projects/glare-removal/sdk-python/runware/base.py", line 2207, in _buildImageRequest
self._addImageProviderSettings(request_object, requestImage)
File "/Users/rsortino/projects/glare-removal/sdk-python/runware/base.py", line 2322, in _addImageProviderSettings
provider_dict = requestImage.providerSettings.to_request_dict()
Code to reproduce
import asyncio
from runware import Runware, IImageInference
import os
import base64
from pathlib import Path
# Get API key from environment variables
API_KEY = os.getenv("RUNWARE_API_KEY")
PROMPT = "Replace the dog with a cat. Keep the background the same."
def encode_image(image_path: str) -> str:
with open(image_path, "rb") as f:
image_data = base64.b64encode(f.read()).decode("utf-8")
ext = Path(image_path).suffix.lower()
mime = "image/jpeg" if ext in {".jpg", ".jpeg"} else f"image/{ext.lstrip('.')}"
return f"data:{mime};base64,{image_data}"
async def main():
runware = Runware(api_key=API_KEY)
await runware.connect()
image_data_uri = encode_image("examples/dalmatian.jpg")
request_params = {
"positivePrompt": PROMPT,
"model": "bfl:7@1",
"width": 1280,
"height": 720,
"includeCost": True,
"inputs": {
"referenceImages": [image_data_uri],
},
}
request = IImageInference(**request_params)
images = await runware.imageInference(request)
print(f"Generated image: {images[0].imageURL}")
if __name__ == "__main__":
asyncio.run(main())A solution would be to assign the "inputs" dict to a IInputs object and then use this in the request, but IMHO it would be cleaner to handle this in the library rather than in the client code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels