mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Merge branch 'SebastianAigner-main' into development
Add support for full CORS headers for dream server.
This commit is contained in:
commit
4406fd138d
@ -16,6 +16,8 @@ class DreamServer(BaseHTTPRequestHandler):
|
|||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
if self.path == "/":
|
if self.path == "/":
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
|
self.send_header("Access-Control-Allow-Origin", "*")
|
||||||
|
self.send_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
||||||
self.send_header("Content-type", "text/html")
|
self.send_header("Content-type", "text/html")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
with open("./static/dream_web/index.html", "rb") as content:
|
with open("./static/dream_web/index.html", "rb") as content:
|
||||||
@ -33,6 +35,8 @@ class DreamServer(BaseHTTPRequestHandler):
|
|||||||
elif self.path == "/cancel":
|
elif self.path == "/cancel":
|
||||||
self.canceled.set()
|
self.canceled.set()
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
|
self.send_header("Access-Control-Allow-Origin", "*")
|
||||||
|
self.send_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
||||||
self.send_header("Content-type", "application/json")
|
self.send_header("Content-type", "application/json")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(bytes('{}', 'utf8'))
|
self.wfile.write(bytes('{}', 'utf8'))
|
||||||
@ -55,6 +59,8 @@ class DreamServer(BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
|
self.send_header("Access-Control-Allow-Origin", "*")
|
||||||
|
self.send_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
||||||
self.send_header("Content-type", "application/json")
|
self.send_header("Content-type", "application/json")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
||||||
@ -199,6 +205,11 @@ class DreamServer(BaseHTTPRequestHandler):
|
|||||||
print(f"Canceled.")
|
print(f"Canceled.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def do_OPTIONS(self):
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header("Access-Control-Allow-Origin", "*")
|
||||||
|
self.send_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
class ThreadingDreamServer(ThreadingHTTPServer):
|
class ThreadingDreamServer(ThreadingHTTPServer):
|
||||||
def __init__(self, server_address):
|
def __init__(self, server_address):
|
||||||
|
@ -297,7 +297,7 @@ class T2I:
|
|||||||
0.0 <= variation_amount <= 1.0
|
0.0 <= variation_amount <= 1.0
|
||||||
), '-v --variation_amount must be in [0.0, 1.0]'
|
), '-v --variation_amount must be in [0.0, 1.0]'
|
||||||
|
|
||||||
if len(with_variations) > 0 or variation_amount > 1.0:
|
if len(with_variations) > 0 or variation_amount > 0.0:
|
||||||
assert seed is not None,\
|
assert seed is not None,\
|
||||||
'seed must be specified when using with_variations'
|
'seed must be specified when using with_variations'
|
||||||
if variation_amount == 0.0:
|
if variation_amount == 0.0:
|
||||||
@ -346,6 +346,7 @@ class T2I:
|
|||||||
callback=step_callback,
|
callback=step_callback,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
init_latent = None
|
||||||
make_image = self._txt2img(
|
make_image = self._txt2img(
|
||||||
prompt,
|
prompt,
|
||||||
steps=steps,
|
steps=steps,
|
||||||
@ -361,11 +362,11 @@ class T2I:
|
|||||||
if variation_amount > 0 or len(with_variations) > 0:
|
if variation_amount > 0 or len(with_variations) > 0:
|
||||||
# use fixed initial noise plus random noise per iteration
|
# use fixed initial noise plus random noise per iteration
|
||||||
seed_everything(seed)
|
seed_everything(seed)
|
||||||
initial_noise = self._get_noise(init_img,width,height)
|
initial_noise = self._get_noise(init_latent,width,height)
|
||||||
for v_seed, v_weight in with_variations:
|
for v_seed, v_weight in with_variations:
|
||||||
seed = v_seed
|
seed = v_seed
|
||||||
seed_everything(seed)
|
seed_everything(seed)
|
||||||
next_noise = self._get_noise(init_img,width,height)
|
next_noise = self._get_noise(init_latent,width,height)
|
||||||
initial_noise = self.slerp(v_weight, initial_noise, next_noise)
|
initial_noise = self.slerp(v_weight, initial_noise, next_noise)
|
||||||
if variation_amount > 0:
|
if variation_amount > 0:
|
||||||
random.seed() # reset RNG to an actually random state, so we can get a random seed for variations
|
random.seed() # reset RNG to an actually random state, so we can get a random seed for variations
|
||||||
@ -377,7 +378,7 @@ class T2I:
|
|||||||
x_T = None
|
x_T = None
|
||||||
if variation_amount > 0:
|
if variation_amount > 0:
|
||||||
seed_everything(seed)
|
seed_everything(seed)
|
||||||
target_noise = self._get_noise(init_img,width,height)
|
target_noise = self._get_noise(init_latent,width,height)
|
||||||
x_T = self.slerp(variation_amount, initial_noise, target_noise)
|
x_T = self.slerp(variation_amount, initial_noise, target_noise)
|
||||||
elif initial_noise is not None:
|
elif initial_noise is not None:
|
||||||
# i.e. we specified particular variations
|
# i.e. we specified particular variations
|
||||||
@ -385,9 +386,8 @@ class T2I:
|
|||||||
else:
|
else:
|
||||||
seed_everything(seed)
|
seed_everything(seed)
|
||||||
if self.device.type == 'mps':
|
if self.device.type == 'mps':
|
||||||
x_T = self._get_noise(init_img,width,height)
|
x_T = self._get_noise(init_latent,width,height)
|
||||||
# make_image will do the equivalent of get_noise itself
|
# make_image will do the equivalent of get_noise itself
|
||||||
print(f' DEBUG: seed at make_image() invocation time ={seed}')
|
|
||||||
image = make_image(x_T)
|
image = make_image(x_T)
|
||||||
results.append([image, seed])
|
results.append([image, seed])
|
||||||
if image_callback is not None:
|
if image_callback is not None:
|
||||||
@ -617,8 +617,8 @@ class T2I:
|
|||||||
return self.model
|
return self.model
|
||||||
|
|
||||||
# returns a tensor filled with random numbers from a normal distribution
|
# returns a tensor filled with random numbers from a normal distribution
|
||||||
def _get_noise(self,init_img,width,height):
|
def _get_noise(self,init_latent,width,height):
|
||||||
if init_img:
|
if init_latent is not None:
|
||||||
if self.device.type == 'mps':
|
if self.device.type == 'mps':
|
||||||
return torch.randn_like(init_latent, device='cpu').to(self.device)
|
return torch.randn_like(init_latent, device='cpu').to(self.device)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user