Skip to content

replicate.run returning FileOutput objects #377

Open

Description

@jacksondc

When I run the code examples in the README, I get back replicate.helpers.FileOutput objects. I expected to get URLs.

Steps to reproduce:

pip install replicate== 1.0.2
export REPLICATE_API_TOKEN=...
python3

>>> import replicate
>>> replicate.run(
...         "stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478",
...         input={"prompt": "a 19th century portrait of a wombat gentleman"}
...     )
[<replicate.helpers.FileOutput object at 0x1062f3e60>]

Looks like the new types were introduced in version 1.0.1.

Activity

  1. paulocoutinhox commented on Oct 18, 2024

    @paulocoutinhox

    Use:

    obj = replicate.run([...])
    print(obj.url)
    
    # or str(obj)
    
  2. user-will commented on Oct 19, 2024

    @user-will

    I am having the same issue. I am getting a file output and am unsure how to parse. The example code does not work for presenting an image.

    
    import replicate
    output = replicate.run(
      "black-forest-labs/flux-schnell",
      input={"prompt": "an african grey parrot sitting in the jungle on a branch, pointillism"}
    )
    
    

    I get these outputs:

    output ---> [<replicate.helpers.FileOutput at 0x21c3cd91f50>]
    str(output) ---> [<replicate.helpers.FileOutput object at 0x0000021C3CD91F50>]
    
    output[0].url ---> data:application/octet-stream;base64,UklGRowqAwBXRUJQV.....
    str(output[0]) ---> data:application/octet-stream;base64,UklGRowqAwBXRUJQV.....
    
    

    I did get it to display an image with:

    from IPython.display import Image
    img = Image(url=output[0].url)
    
  3. user-will commented on Oct 19, 2024

    @user-will

    It appears that the FileOutput class was only added last month and is a completely new addition. Likely the cause of the problems here.

    Here is a link to the commit: e7f699f

    Link to file: https://github.com/replicate/replicate-python/blob/main/replicate/helpers.py

  4. user-will commented on Oct 19, 2024

    @user-will

    I got it to output the correct delivery url when I downgraded my replicate version to 0.32.1 (before the FileOutput commit).

    Just install the older version then restart your kernel.

    https://pypi.org/project/replicate/0.32.1/

  5. xuyannus commented on Oct 19, 2024

    @xuyannus

    this testing code does not work:

    import requests
    
    output = replicate.run(
        "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
        input={"text": "an astronaut riding a horse"}
    )
    
    response = requests.get(output[0].url)
    
    with open("local_image.jpg", "wb") as file:
        file.write(response.content)
    
  6. user-will commented on Oct 19, 2024

    @user-will

    @xuyannus Try removing .url from output[0] and just doing:

    import requests
    
    output = replicate.run(
        "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
        input={"text": "an astronaut riding a horse"}
    )
    
    response = requests.get(output[0])
    
    with open("local_image.jpg", "wb") as file:
        file.write(response.content)
    

    I also downgraded to v0.32.1 to get mine to work. https://pypi.org/project/replicate/0.32.1/

  7. aron commented on Oct 21, 2024

    @aron
    Contributor

    Thanks for the feedback all, we'll get the examples in the README fixed.

    As mentioned in the issue the URL can be accessed via the url attribute on the FileOutput object.

    import replicate
    output = replicate.run(
      "black-forest-labs/flux-schnell",
      input={"prompt": "an african grey parrot sitting in the jungle on a branch, pointillism"}
    )
    print(output[0].url)

    @xuyannus

    this testing code does not work:

    import requests
    ...
    

    The requests library is not needed to fetch the output.

    import replicate
    
    output = replicate.run(
        "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
        input={"text": "an astronaut riding a horse"}
    )
    
    with open("local_image.jpg", "wb") as file:
        file.write(output[0])
  8. melvinmt commented on Oct 22, 2024

    @melvinmt

    FYI: This breaking change caused all our API integrations with replicate to stop working…

    @aron the documentation on the model pages also have no mention of the FileOutput: https://replicate.com/black-forest-labs/flux-1.1-pro/api

  9. paulocoutinhox commented on Oct 23, 2024

    @paulocoutinhox

    The technical team is very bad. There is no consistency, everything stops working out of nowhere. Now, I'm getting another problem. The "url" field returns in base64 and not the URL itself.

  10. eloelo-techadmin commented on Oct 24, 2024

    @eloelo-techadmin

    @paulocoutinhox I am getting the same issue. Our inference API has stopped working. @aron Can you guys please check this asap?

  11. user-will commented on Oct 26, 2024

    @user-will

    I was not able to fix the problem with the latest package version. Same problems with the base64. Clearly more needs to be worked out on the backend side.

    For now I have been able to get it to work as intended in the code examples by downgrading to version 0.23.1 https://pypi.org/project/replicate/0.32.1/

    Hope this helps and gets resolved in the latest versions. For now just downgrade to v0.23.1 unless it causes other issues.

    @eloelo-techadmin @melvinmt @paulocoutinhox

  12. paulocoutinhox commented on Oct 26, 2024

    @paulocoutinhox

    Hi @user-will,

    Im using this:

    output = replicate.run(model_path, input=replicate_input)
    
    # get the output format for file extension
    output_format = flux_model_task.output_format.lower()
    
    # download and save the generated image
    for output_item in output:
        unique_file_name = f"{uuid.uuid4()}.{output_format}"
        file_content = ContentFile(output_item.read())
    
        flux_model_task.output_image.save(unique_file_name, file_content, save=True)
    
        # mark the task as processed
        flux_model_task.status = GenerationStatus.PROCESSED
        flux_model_task.save()
    
        logger.info(f"Generated image saved: {unique_file_name}")
  13. ikergarcia1996 commented on Oct 28, 2024

    @ikergarcia1996

    @aron Neither output.url nor use_file_output=False works. I still get the output in base64 format

    [output] = replicate.run(
    "black-forest-labs/flux-schnell",
     input={"prompt": "astronaut riding a rocket like a horse"},
    use_file_output=False)
    
    print(output)
    # BASE64 data
    output = replicate.run(
    "black-forest-labs/flux-schnell",
    input={"prompt": "an african grey parrot sitting in the jungle on a branch, pointillism"}
    )
    
    print(output[0].url)
    
    #BASE64 data

    Downgrading to version 0.34.1 works for now. The documentation does not reference the new API, which is very confusing: https://replicate.com/black-forest-labs/flux-1.1-pro/api

  14. ntindle commented on Oct 28, 2024

    @ntindle

    I'd update the release notes on 1.0.0 to note its FileOutput as seen above or FileObject. If it is FileObject, setup type hints in the future rather than returning Any | list[Any] from your library plz :)

    Here's a quick example of how to do it for sync API #389

  15. paulocoutinhox commented on Oct 29, 2024

    @paulocoutinhox

    My solution is working on new versions too. Thanks.

  16. Skquark commented on Dec 8, 2024

    @Skquark

    So now it looks like the output is no longer a list, and if you try to use output[0].url or iterate on it, lets you know FileOutput is not Subscribable. Easy enough to do output.url now that we know, I'm still doing it with output = [output.url] to keep it as a str list in case the pipelines add a num_images batch option, but it's fine. I now have most of the main Replicate APIs integrated into my app at AEIONic.com with all the bells & whistles..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions