stable-diffusion icon indicating copy to clipboard operation
stable-diffusion copied to clipboard

Free Stable Diffusion API?

Open incomingflyingbrick opened this issue 2 years ago • 50 comments

I fount a free stable diffusion api from this site https://www.wizmodel.com/docs/sdApi is this the official API?

incomingflyingbrick avatar Sep 07 '23 06:09 incomingflyingbrick

execuse me,i got the result of the interface /sdapi/v1/txt2img,but how can i use it image

wang-xiaowu avatar Sep 13 '23 09:09 wang-xiaowu

Hi Xiaowu, You can use the code below to show the image. The image from SD is base64 encoded, so you have to decode it to bytes before you can use it or save it or show it. Let me know if you still have question

import requests
import json
from PIL import Image
from io import BytesIO
import base64

url = "https://api.wizmodel.com/sdapi/v1/txt2img"

payload = json.dumps({
  "prompt": "puppy dog running on grass",
  "steps": 50
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <YOUR_API_KEY>'
}

response = requests.request("POST", url, headers=headers, data=payload)

# Example base64 string (replace with your own)
base64_string = response.json()['images'][0]

# Decode the base64 string into bytes
image_data = base64.b64decode(base64_string)
image_bytes = BytesIO(image_data)

# Open and display the image using Pillow
image = Image.open(image_bytes)
image.show()

# Save the image to a local file
image.save("output_image.jpg")

incomingflyingbrick avatar Sep 14 '23 05:09 incomingflyingbrick

I just reply to your question, please check it out on github.

On Wed, Sep 13, 2023 at 5:48 PM xiaowu @.***> wrote:

execuse me,i got the result of the interface /sdapi/v1/txt2img,but how can i use it [image: image] https://user-images.githubusercontent.com/44340137/267610766-c641ecdf-5ce7-49d6-8561-d0c996137b78.png

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/795#issuecomment-1717306191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELYV6QEOHP3KLLAKDVMQOLX2F6OVANCNFSM6AAAAAA4OMCG3M . You are receiving this because you authored the thread.Message ID: @.***>

incomingflyingbrick avatar Sep 14 '23 05:09 incomingflyingbrick

thx i will check it out later

wang-xiaowu avatar Sep 14 '23 05:09 wang-xiaowu

Hi Xiaowu, You can use the code below to show the image. The image from SD is base64 encoded, so you have to decode it to bytes before you can use it or save it or show it. Let me know if you still have question

import requests
import json
from PIL import Image
from io import BytesIO
import base64

url = "https://api.wizmodel.com/sdapi/v1/txt2img"

payload = json.dumps({
  "prompt": "puppy dog running on grass",
  "steps": 50
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <YOUR_API_KEY>'
}

response = requests.request("POST", url, headers=headers, data=payload)

# Example base64 string (replace with your own)
base64_string = response.json()['images'][0]

# Decode the base64 string into bytes
image_data = base64.b64decode(base64_string)
image_bytes = BytesIO(image_data)

# Open and display the image using Pillow
image = Image.open(image_bytes)
image.show()

# Save the image to a local file
image.save("output_image.jpg")

hi, i try this, and the response.status_code is 502. Is something wrong?

richiy avatar Sep 26 '23 13:09 richiy

Hi Xiaowu, You can use the code below to show the image. The image from SD is base64 encoded, so you have to decode it to bytes before you can use it or save it or show it. Let me know if you still have question

import requests
import json
from PIL import Image
from io import BytesIO
import base64

url = "https://api.wizmodel.com/sdapi/v1/txt2img"

payload = json.dumps({
  "prompt": "puppy dog running on grass",
  "steps": 50
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <YOUR_API_KEY>'
}

response = requests.request("POST", url, headers=headers, data=payload)

# Example base64 string (replace with your own)
base64_string = response.json()['images'][0]

# Decode the base64 string into bytes
image_data = base64.b64decode(base64_string)
image_bytes = BytesIO(image_data)

# Open and display the image using Pillow
image = Image.open(image_bytes)
image.show()

# Save the image to a local file
image.save("output_image.jpg")

hi, i try this, and the response.status_code is 502. Is something wrong?

Hi , Could you post the error message and response here?

incomingflyingbrick avatar Sep 29 '23 00:09 incomingflyingbrick

Hi Xiaowu, You can use the code below to show the image. The image from SD is base64 encoded, so you have to decode it to bytes before you can use it or save it or show it. Let me know if you still have question

import requests
import json
from PIL import Image
from io import BytesIO
import base64

url = "https://api.wizmodel.com/sdapi/v1/txt2img"

payload = json.dumps({
  "prompt": "puppy dog running on grass",
  "steps": 50
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <YOUR_API_KEY>'
}

response = requests.request("POST", url, headers=headers, data=payload)

# Example base64 string (replace with your own)
base64_string = response.json()['images'][0]

# Decode the base64 string into bytes
image_data = base64.b64decode(base64_string)
image_bytes = BytesIO(image_data)

# Open and display the image using Pillow
image = Image.open(image_bytes)
image.show()

# Save the image to a local file
image.save("output_image.jpg")

hi, i try this, and the response.status_code is 502. Is something wrong?

Hi , Could you post the error message and response here?

It works now. It may be a problem with my proxy settings. Thx.

richiy avatar Sep 30 '23 02:09 richiy

Great, good to know

On Sat, Sep 30, 2023 at 10:02 AM richiy @.***> wrote:

Hi Xiaowu, You can use the code below to show the image. The image from SD is base64 encoded, so you have to decode it to bytes before you can use it or save it or show it. Let me know if you still have question

import requestsimport jsonfrom PIL import Imagefrom io import BytesIOimport base64 url = "https://api.wizmodel.com/sdapi/v1/txt2img" payload = json.dumps({ "prompt": "puppy dog running on grass", "steps": 50 })headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer <YOUR_API_KEY>' } response = requests.request("POST", url, headers=headers, data=payload)

Example base64 string (replace with your own)base64_string = response.json()['images'][0]

Decode the base64 string into bytesimage_data = base64.b64decode(base64_string)image_bytes = BytesIO(image_data)

Open and display the image using Pillowimage = Image.open(image_bytes)image.show()

Save the image to a local fileimage.save("output_image.jpg")

hi, i try this, and the response.status_code is 502. Is something wrong?

Hi , Could you post the error message and response here?

It works now. It may be a problem with my proxy settings. Thx.

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/795#issuecomment-1741628734, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELYV6SJQOWL2HNZ5EJI44LX454R3ANCNFSM6AAAAAA4OMCG3M . You are receiving this because you modified the open/close state.Message ID: @.***>

incomingflyingbrick avatar Sep 30 '23 02:09 incomingflyingbrick

Hi Xiaowu, You can use the code below to show the image. The image from SD is base64 encoded, so you have to decode it to bytes before you can use it or save it or show it. Let me know if you still have question

import requests
import json
from PIL import Image
from io import BytesIO
import base64

url = "https://api.wizmodel.com/sdapi/v1/txt2img"

payload = json.dumps({
  "prompt": "puppy dog running on grass",
  "steps": 50
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <YOUR_API_KEY>'
}

response = requests.request("POST", url, headers=headers, data=payload)

# Example base64 string (replace with your own)
base64_string = response.json()['images'][0]

# Decode the base64 string into bytes
image_data = base64.b64decode(base64_string)
image_bytes = BytesIO(image_data)

# Open and display the image using Pillow
image = Image.open(image_bytes)
image.show()

# Save the image to a local file
image.save("output_image.jpg")

hi, i try this, and the response.status_code is 502. Is something wrong?

Hi , Could you post the error message and response here?

It works now. It may be a problem with my proxy settings. Thx.

It not work again. Got error message: requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

richiy avatar Oct 08 '23 13:10 richiy

Hi, Richiy, could you try again? It's working now. The server was done this morning. sorry about that.

On Sun, Oct 8, 2023 at 10:00 PM richiy @.***> wrote:

Hi Xiaowu, You can use the code below to show the image. The image from SD is base64 encoded, so you have to decode it to bytes before you can use it or save it or show it. Let me know if you still have question

import requestsimport jsonfrom PIL import Imagefrom io import BytesIOimport base64 url = "https://api.wizmodel.com/sdapi/v1/txt2img" payload = json.dumps({ "prompt": "puppy dog running on grass", "steps": 50 })headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer <YOUR_API_KEY>' } response = requests.request("POST", url, headers=headers, data=payload)

Example base64 string (replace with your own)base64_string = response.json()['images'][0]

Decode the base64 string into bytesimage_data = base64.b64decode(base64_string)image_bytes = BytesIO(image_data)

Open and display the image using Pillowimage = Image.open(image_bytes)image.show()

Save the image to a local fileimage.save("output_image.jpg")

hi, i try this, and the response.status_code is 502. Is something wrong?

Hi , Could you post the error message and response here?

It works now. It may be a problem with my proxy settings. Thx.

It not work again. Got error message: requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/795#issuecomment-1752035536, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELYV6QYGDIMETFRHSKQBS3X6KWWRAVCNFSM6AAAAAA4OMCG3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJSGAZTKNJTGY . You are receiving this because you modified the open/close state.Message ID: @.***>

incomingflyingbrick avatar Oct 09 '23 00:10 incomingflyingbrick

Hi, Richiy, could you try again? It's working now. The server was done this morning. sorry about that. On Sun, Oct 8, 2023 at 10:00 PM richiy @.> wrote: Hi Xiaowu, You can use the code below to show the image. The image from SD is base64 encoded, so you have to decode it to bytes before you can use it or save it or show it. Let me know if you still have question import requestsimport jsonfrom PIL import Imagefrom io import BytesIOimport base64 url = "https://api.wizmodel.com/sdapi/v1/txt2img" payload = json.dumps({ "prompt": "puppy dog running on grass", "steps": 50 })headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer <YOUR_API_KEY>' } response = requests.request("POST", url, headers=headers, data=payload) # Example base64 string (replace with your own)base64_string = response.json()['images'][0] # Decode the base64 string into bytesimage_data = base64.b64decode(base64_string)image_bytes = BytesIO(image_data) # Open and display the image using Pillowimage = Image.open(image_bytes)image.show() # Save the image to a local fileimage.save("output_image.jpg") hi, i try this, and the response.status_code is 502. Is something wrong? Hi , Could you post the error message and response here? It works now. It may be a problem with my proxy settings. Thx. It not work again. Got error message: requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) — Reply to this email directly, view it on GitHub <#795 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELYV6QYGDIMETFRHSKQBS3X6KWWRAVCNFSM6AAAAAA4OMCG3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJSGAZTKNJTGY . You are receiving this because you modified the open/close state.Message ID: @.>

It's working now. Thx!

richiy avatar Oct 09 '23 02:10 richiy

{ "error": "OutOfMemoryError", "detail": "", "body": "", "errors": "CUDA out of memory. Tried to allocate 2.00 MiB (GPU 0; 22.19 GiB total capacity; 21.24 GiB already allocated; 1.50 MiB free; 21.79 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF" }

ainsteen01 avatar Oct 23 '23 08:10 ainsteen01

Fixed!

On Mon, Oct 23, 2023 at 4:43 PM Ainsteen Varghese @.***> wrote:

{ "error": "OutOfMemoryError", "detail": "", "body": "", "errors": "CUDA out of memory. Tried to allocate 2.00 MiB (GPU 0; 22.19 GiB total capacity; 21.24 GiB already allocated; 1.50 MiB free; 21.79 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF" }

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/795#issuecomment-1774706929, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELYV6RPHJ6M56ICJSOKJRTYAYU35AVCNFSM6AAAAAA4OMCG3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZUG4YDMOJSHE . You are receiving this because you modified the open/close state.Message ID: @.***>

incomingflyingbrick avatar Oct 24 '23 06:10 incomingflyingbrick

Thanks now its working

ainsteen01 avatar Oct 24 '23 06:10 ainsteen01

Hello! I'm a bit of a newbie, so I don't understand all the nuances. The Python code is working, but the C# code I need is not cooperating. I tried to make everything without asynchronous processing, as it was written in the documentation, could you help me figure it out? using System; using System.IO; using System.Net; using System.Text;

class Program { static void Main() { string url = "https://api.wizmodel.com/sdapi/v1/txt2img";

    // Подготовка данных для POST-запроса
    string postData = "{\"prompt\":\"puppy dog running on grass\",\"steps\":50}";
    byte[] data = Encoding.UTF8.GetBytes(postData);

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "POST";
    request.ContentType = "application/json";
    request.Headers.Add("Authorization", "Bearer <MyApi c> >");

    using (Stream requestStream = request.GetRequestStream())
    {
        requestStream.Write(data, 0, data.Length);
    }

    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    using (Stream dataStream = response.GetResponseStream())
    using (StreamReader reader = new StreamReader(dataStream))
    {
        string responseText = reader.ReadToEnd();
        Console.WriteLine(responseText);
    }
}

} Of course, I enter my API key, but I keep getting this message. {"code":403,"msg":"Access denied: API-Key invalid","data":{}}

LeognidusW avatar Oct 25 '23 16:10 LeognidusW

Hello Leognidus you can try the following C# code. It might work.

using System; using System.Net.Http; using System.Text; // for Encoding.UTF8 using System.Threading.Tasks; // for async Task using Newtonsoft.Json.Linq; // for JObject. Make sure to install the Newtonsoft.Json package.

class Program { private static readonly string ApiKey = "<YOUR_API_KEY>"; private const string Url = "https://api.wizmodel.com/sdapi/v1/txt2img";

static async Task Main()
{
    using var client = new HttpClient();

    // Prepare headers
    client.DefaultRequestHeaders.Add("Authorization", "Bearer " +

ApiKey); client.DefaultRequestHeaders.Add("Content-Type", "application/json");

    // Create payload
    var payload = new JObject
    {
        ["prompt"] = "puppy dog running on grass",
        ["steps"] = 100
    };

    var response = await client.PostAsync(Url, new

StringContent(payload.ToString(), Encoding.UTF8, "application/json"));

    if (response.IsSuccessStatusCode)
    {
        var jsonResponse = await response.Content.ReadAsStringAsync();
        Console.WriteLine(jsonResponse);
    }
    else
    {
        Console.WriteLine($"Error: {response.StatusCode}");
    }
}

}

On Thu, Oct 26, 2023 at 12:54 AM LeognidusW @.***> wrote:

Hello! I'm a bit of a newbie, so I don't understand all the nuances. The Python code is working, but the C# code I need is not cooperating. I tried to make everything without asynchronous processing, as it was written in the documentation, could you help me figure it out? using System; using System.IO; using System.Net; using System.Text;

class Program { static void Main() { string url = "https://api.wizmodel.com/sdapi/v1/txt2img";

// Подготовка данных для POST-запроса
string postData = "{\"prompt\":\"puppy dog running on grass\",\"steps\":50}";
byte[] data = Encoding.UTF8.GetBytes(postData);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.Headers.Add("Authorization", "Bearer <MyApi c> >");

using (Stream requestStream = request.GetRequestStream())
{
    requestStream.Write(data, 0, data.Length);
}

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream dataStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(dataStream))
{
    string responseText = reader.ReadToEnd();
    Console.WriteLine(responseText);
}

}

} Of course, I enter my API key, but I keep getting this message. {"code":403,"msg":"Access denied: API-Key invalid","data":{}}

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/795#issuecomment-1779683736, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELYV6SF5BKP75JKEGVPI3TYBE74DAVCNFSM6AAAAAA4OMCG3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZZGY4DGNZTGY . You are receiving this because you modified the open/close state.Message ID: @.***>

incomingflyingbrick avatar Oct 26 '23 00:10 incomingflyingbrick

Hey bro , how are you? This api works good? Are the images good? Can I run it on swift UI? this is gold

SANTINO27 avatar Oct 27 '23 04:10 SANTINO27

Hi SANTINO27, The API is working as expected. The image is good or not depends on what prompt you entered, the more detailed prompt the better. Yes, it doesn't work on Swift UI as long as you can send a simple HTTP POST request to the API :)

On Fri, Oct 27, 2023 at 12:21 PM SANTINO27 @.***> wrote:

Hey bro , how are you? This api works good? Are the images good? Can I run it on swift UI? this is gold

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/795#issuecomment-1782267926, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELYV6UCUHMOMP3Z56J663TYBMZEFAVCNFSM6AAAAAA4OMCG3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBSGI3DOOJSGY . You are receiving this because you modified the open/close state.Message ID: @.***>

incomingflyingbrick avatar Nov 01 '23 01:11 incomingflyingbrick

If you use jupyter you can do

`import base64 from IPython import display

js = response.json() base64_string = js['images'][0] image_data = base64.b64decode(base64_string)

display.display(display.Image(data=image_data))`

kshabanaa avatar Nov 13 '23 17:11 kshabanaa

I noticed the api is giving the same image every time. Is there a seed option for this api?

TommyDong1998 avatar Nov 18 '23 12:11 TommyDong1998

"I noticed the api is giving the same image every time. Is there a seed option for this api?" We will try to add that

On Sat, Nov 18, 2023 at 8:37 PM Tommy Dong @.***> wrote:

I noticed the api is giving the same image every time. Is there a seed option for this api?

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/795#issuecomment-1817497752, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELYV6XT3GBQAJKPGDZBRALYFCTXBAVCNFSM6AAAAAA4OMCG3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJXGQ4TONZVGI . You are receiving this because you modified the open/close state.Message ID: @.***>

incomingflyingbrick avatar Nov 19 '23 15:11 incomingflyingbrick

The api is giving same image for the same text

ainsteen01 avatar Nov 19 '23 16:11 ainsteen01

The api is giving same image for the same text

I added a seed, it should now output random picture everytime.

incomingflyingbrick avatar Nov 20 '23 01:11 incomingflyingbrick

I noticed the api is giving the same image every time. Is there a seed option for this api?

I added a seed, it should now output random picture everytime for you.

incomingflyingbrick avatar Nov 20 '23 01:11 incomingflyingbrick

Good day! Denoising_strength stopped working in the img2img Wizmodel API. Now the API responds with some random images. Is there any way to make it work again?

I will take a look today

incomingflyingbrick avatar Nov 21 '23 00:11 incomingflyingbrick

Good day! Denoising_strength stopped working in the img2img Wizmodel API. Now the API responds with some random images. Is there any way to make it work again?

Hi Metim0l, I just tried the "denoising strength" parameter, it is working fine. Did you change your code recently? or You could upload your code here to see if there is anything wrong with it.

incomingflyingbrick avatar Nov 21 '23 00:11 incomingflyingbrick

Good day! Denoising_strength stopped working in the img2img Wizmodel API. Now the API responds with some random images. Is there any way to make it work again?

Btw this parameter's value is between 0 and 1 inclusive.

incomingflyingbrick avatar Nov 21 '23 01:11 incomingflyingbrick

Good day! Denoising_strength stopped working in the img2img Wizmodel API. Now the API responds with some random images. Is there any way to make it work again?

Hi Metim0l, May I know what application you are building so that you need to the "denoising strength" parameter, thz.

incomingflyingbrick avatar Nov 21 '23 15:11 incomingflyingbrick

Hi @incomingflyingbrick Have you changed the txt2img model recently? I have the impression that the images have lost quality..

valentin19 avatar Nov 22 '23 21:11 valentin19

Hi @valentin19 I noticed that. The refiner is not working properly. I am working on it right now , tring to fix it ASAP. Thank you.

incomingflyingbrick avatar Nov 23 '23 00:11 incomingflyingbrick