Skip to content

[Inference] get the raw response for textToImage #1617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

krampstudio
Copy link
Collaborator

@krampstudio krampstudio commented Jul 11, 2025

Allow to get the full response for text-to-image inference, instead of directly the blob or the url:

const res = await textToImage({ inputs:  "A dog with a baseball cap" },{ outputType: "json" });

we have the following ouput (depends on the provider)

{
  "images": [
    {
      "url": "data:image/png;base64,iVBORw0KGgoAAAAN......rkJggg==",
      "width": 1024,
      "height": 768,
      "content_type": "image/png"
    }
  ],
  "timings": {
    "inference": 1.2445615287870169
  },
  "seed": 982874191,
  "has_nsfw_concepts": [
    false
  ],
  "prompt": "A dog with a baseball cap"
} 

needed for (internal https://github.com/huggingface-internal/moon-landing/pull/14421)

@coyotte508
Copy link
Member

coyotte508 commented Jul 11, 2025

Why do we need that?

In the internal link, we only do const imageBlob = isImage(res) ? res : new Blob([res], { type: "image/png" }); so it seems we could just call textToImage with output: "blob" ?

@krampstudio
Copy link
Collaborator Author

krampstudio commented Jul 11, 2025

Why do we need that?

In the internal link, we only do const imageBlob = isImage(res) ? res : new Blob([res], { type: "image/png" }); so it seems we could just call textToImage with output: "blob" ?

I've updated the internal link, we need the full response for educational purpose: we show it to the user.

And more generaly, it can be usefull for developers to access the full response.

Copy link
Member

@julien-c julien-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no objection on my side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants