Open incomingflyingbrick opened 1 year ago
execuse me,i got the result of the interface /sdapi/v1/txt2img
,but how can i use it
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")
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: @.***>
thx i will check it out later
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 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?
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.
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
' } 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: @.***>
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'))
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
' } 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: @.***>
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
' } 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!
{ "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" }
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: @.***>
Thanks now its working
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":{}}
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 = "
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: @.***>
Hey bro , how are you? This api works good? Are the images good? Can I run it on swift UI? this is gold
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: @.***>
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))`
I noticed the api is giving the same image every time. Is there a seed option for this api?
"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: @.***>
The api is giving same image for the same text
The api is giving same image for the same text
I added a seed, it should now output random picture everytime.
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.
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
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.
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.
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.
Hi @incomingflyingbrick Have you changed the txt2img model recently? I have the impression that the images have lost quality..
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.
Hello @incomingflyingbrick
Does the img2img model still work? Because I get an internal server error.
Hi Metim0l, the img2img api is down due to high demand right now. I am trying to bring it back up, it should be back up in 1 or 2 days. Thanks.
I cannot fetch via JS by CORS policy, can you fix that by allowing requests from other domains?
Solved that by using a proxy, but I would really appreciate to not have to use it. Thanks!
Solved that by using a proxy, but I would really appreciate to not have to use it. Thanks!
Hi it's solved, it should be working now with out a proxy.
The API stopped working completely 😢
HI Meti0l, I just added a new API for the img2img gen. You can use the following api to generate an image, it's using StableDiffusion-2. This API is using a preemptive GPU, so the first time you call this API there could be a wait time for requesting a GPU plus model loading time( like 15 minutes). When the model is loaded the second inference should be very fast (like 10-20 seconds).
import requests
import json
url = "https://api.wizmodel.com/v1/predictions"
payload = json.dumps({
"input": {
"prompt": "Astronaut in a jungle, cold color palette, muted colors, detailed",
"denoising_strength": 0.8,
"guidance_scale": 10,
"init_image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png"
},
"version": "fbe05661e1ab10b6e4c13908a3e55381e950b2904582cd55240b7733d59b14e6"
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <YOUR_API_KEY_HERE>'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Solved that by using a proxy, but I would really appreciate to not have to use it. Thanks!
Hi it's solved, it should be working now with out a proxy.
thanks!
Hi, can you tell me. For some reason, my response to the request looks like this
{'images': ['eyJlcnJvciI6Ik1vZGVsIHN0YWJpbGl0eWFpL3N0YWJsZS1kaWZmdXNpb24tMi0xIGlzIGN1cnJlbnRseSBsb2FkaW5nIiwiZXN0aW1hdGVkX3RpbWUiOjcyNi43Njk0NzAyMTQ4NDM4fQ==']}
why is it too short
Hi, can you tell me. For some reason, my response to the request looks like this
{'images': ['eyJlcnJvciI6Ik1vZGVsIHN0YWJpbGl0eWFpL3N0YWJsZS1kaWZmdXNpb24tMi0xIGlzIGN1cnJlbnRseSBsb2FkaW5nIiwiZXN0aW1hdGVkX3RpbWUiOjcyNi43Njk0NzAyMTQ4NDM4fQ==']}
why is it too short
Hi, Mamin8002, this is because the model is loading. That's why it's so short. It would take about 10 mins to load the model if the model is in sleep mode. The reason it's sleeping is because we are trying to save GPU resource when the demand is not that high, so it would automatically put the model to sleep. The model will awaken if someone send a http request to the model for inference, note it would take about 10 mins to awaken the model.
@incomingflyingbrick What do you think is the best way to avoid getting these short base64 strings? I use this API in a loop (python) and I use sleep for around 2 minutes between each call, if I used sleep for 10 minutes before beginning the loop itself would it fix the problem?
First solution is Checking the length of a base64 would work, cause base64 str are usually very long. The second solution is I will return a error msg instead of return a base64 string. I will be working on the second solution in a few days.
@MazenMamdouh371 sleeping for 10mins before the call would work.
Hi, can i adjust resolution?
Tried this api several times hopefully, and checking everything entered. The only response recieved is on the screen attached. Sorry.
Tried this api several times hopefully, and checking everything entered. The only response recieved is on the screen attached. Sorry.
@Feyeepop You are puting header in the wrong place, delete the header and put the header in the Authorization tab, see picture below
Hi, can i adjust resolution?
@unblock7 I will try to make this work. give me a few days
Thanks for the attention. A few more tries.
Hi you should remove the header (line 7-10), then it should work @Feyeepop
Thanks for the attention. The time passed, everything checked.
@Feyeepop replace url with this https://api.wizmodel.com/v1/predictions
where to get available models
I fount a free stable diffusion api from this site https://www.wizmodel.com/docs/sdApi is this the official API?