Commit 53864bfe authored by kurumuz's avatar kurumuz

limits

parent 5a7f99ce
import requests
import json
import base64
from PIL import Image
import io
#server hosts on 0.0.0.0
IP_ADDR = '0.0.0.0'
PORT = '4315'
masks = [
{
"seed": 811708258,
"mask": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAKtJREFUeF7t2LENxDAMA0Br/6GVCf4rNQQvAxiBYPEIz+7uK/7GANwAKyADijPwCUEKUIACFKBA8QR+MjgzryEf9QA9oOGe/8k4K2AFrIAqrAoXF0EPIhjEIAYxiEEMFk8AgxjEIAZjGbx4uY4OwfoBXOgdfQMM4GACboAipAgpQrFF6CADvQpTgAIUoAAFLjhJPYMCFKAABSiQmuAX/00BClCAAhS4SNPUMz4jPAhQiCYcNQAAAABJRU5ErkJggg=="
}
]
payload = {
'prompt': 'Hello World',
'prompt': 'test',
"width": 512,
"height": 512,
"scale": 12,
......@@ -15,13 +25,12 @@ payload = {
"n_samples": 1,
"strength": 0.7,
"noise": 0.6,
"masks": [
{
"seed": 2023444088,
"mask": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAKtJREFUeF7t2LENxDAMA0Br/6GVCf4rNQQvAxiBYPEIz+7uK/7GANwAKyADijPwCUEKUIACFKBA8QR+MjgzryEf9QA9oOGe/8k4K2AFrIAqrAoXF0EPIhjEIAYxiEEMFk8AgxjEIAZjGbx4uY4OwfoBXOgdfQMM4GACboAipAgpQrFF6CADvQpTgAIUoAAFLjhJPYMCFKAABSiQmuAX/00BClCAAhS4SNPUMz4jPAhQiCYcNQAAAABJRU5ErkJggg=="
}
]
"masks": None
}
response = requests.post('http://' + IP_ADDR + ':' + PORT + '/generate-stream', json=payload)
print(response.text)
\ No newline at end of file
response = requests.post('http://' + IP_ADDR + ':' + PORT + '/generate', json=payload)
response = response.json()
response = response['output'][0]
response = base64.b64decode(response)
response = Image.open(io.BytesIO(response))
response.save("test1.png")
\ No newline at end of file
......@@ -283,7 +283,7 @@ class StableDiffusionModel(nn.Module):
# convert RGB or grayscale image into 4-channel
mask = mask[0].unsqueeze(0)
mask = torch.repeat_interleave(mask, request.latent_channels, dim=0)
mask = (mask > 0.5).float()
mask = (mask < 0.5).float()
# interpolate start noise
noise_x = (noise_x * (1-mask)) + (sample_start_noise_special(mask_seed+seed_offset, request, self.device) * mask)
......
......@@ -61,6 +61,19 @@ def closest_multiple(num, mult):
return floor if (num_int - floor) < (ceil - num_int) else ceil
def sanitize_stable_diffusion(request, config):
if request.steps > 50:
return False, "steps must be smaller than 50"
pixels = request.height * request.width
if (pixels > 1024*512 and pixels <= 1024*1204) and request.n_samples > 1:
return False, "n_samples must be 1 or smaller at this resolution"
if (pixels > 512*512 and pixels <= 1024*512) and request.n_samples > 2:
return False, "n_samples must be 2 or smaller this resolution"
if (pixels > 256*256 and pixels <= 512*512) and request.n_samples > 4:
return False, "n_samples must be 4 or smaller at this resolution"
if request.width * request.height == 0:
return False, "width and height must be non-zero"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment