Skip to content
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

error :400 while on POST request #5

Open
RohitAggarwal04 opened this issue Apr 11, 2023 · 8 comments
Open

error :400 while on POST request #5

RohitAggarwal04 opened this issue Apr 11, 2023 · 8 comments

Comments

@RohitAggarwal04
Copy link

IDk whats wrong but something i figured problem must be in response probably a new format to make request .

async function generateImage() {
    console.log("generating...");
    const URL = `https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2`;
    const response = await axios({
        url: URL,
        method: "POST",
        headers: {
            Authorization: `Bearer ${process.env.HUGGING_FACE_API_KEY}`,
            Accept: "application/json",
            "Content-Type": "application/json",
        },
        data: JSON.stringify({
            inputs: description,
            options: { wait_for_model: true },
        }),
        responseType: "arraybuffer",
    });

    const type = response.headers["content-type"];
    const data = response.data;

    const base64data = Buffer.from(data).toString("base64");
    const img = `data:${type};base64,` + base64data; // <-- This is so we can render it on the page
    setImage(img);

    return data;
}

Screenshot 2023-04-11 181019

@MhAliCakmak
Copy link

I get some problem
did you find solve?

@RohitAggarwal04
Copy link
Author

Please explain the error

@MhAliCakmak
Copy link

I actually got the same error but I couldn't find the solution

@MhAliCakmak
Copy link

I think we get the error because it does not read data in the .env file. Can you manually write the api key directly in the code?

@MhAliCakmak
Copy link

and you are getting an error because this api key cannot be reached, check your .env file

@RohitAggarwal04
Copy link
Author

I have tried hardcoding it in the file but it didn't worked

@MhAliCakmak
Copy link

you created hugging face api with write option right

@RohitAggarwal04
Copy link
Author

Yes

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

No branches or pull requests

2 participants