Last active
July 29, 2023 19:43
-
-
Save twobob/edb40960ab49a7ad6d932201179f0da0 to your computer and use it in GitHub Desktop.
Revisions
-
twobob revised this gist
Aug 23, 2022 . No changes.There are no files selected for viewing
-
twobob revised this gist
Aug 23, 2022 . 1 changed file with 26 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,13 +22,13 @@ def image_grid(imgs, rows, cols): # can be any whole number above 0 manual_seed = 1024 #@param {type: 'integer'} # make it divisible by your column count and your row count image_count = 9 #@param {type: 'integer'} # how may we add each time we do a new image step_increase = 12 #@param {type: 'integer'} # jump over the first few steps to avoid NSFW flag NSFW_skip_start_step = 10 #@param {type: 'integer'} height = 512 #@param {type: 'integer'} width = 1088 #@param {type: 'integer'} guidance_scale =8 #@param {type: 'integer'} # we are ready to prompt. @@ -39,17 +39,36 @@ def image_grid(imgs, rows, cols): current_steps = NSFW_skip_start_step for i in range(image_count): with autocast("cuda"): #eugh hack time - skip the known bad step iterators. if(current_steps == 9): current_steps = 10 if(current_steps >26 and current_steps<30): current_steps = 30 if(current_steps >100 and current_steps<125): current_steps = 125 if(current_steps >35 and current_steps<40): current_steps = 40 if(current_steps >300 and current_steps<350): current_steps = 350 title = str(current_steps) generator = torch.Generator("cuda").manual_seed(manual_seed) try: img = pipe(prompt, generator=generator, height=height, width=width, num_inference_steps=current_steps, guidance_scale=guidance_scale )["sample"][0] finally: #document every fail current_steps draw = ImageDraw.Draw(img) draw.text((width/2, 50), title, (255,255,255),font=font) #img.save('/content/MyDrive/uniquename.jpg') TODO images.append(img) current_steps += step_increase #single, double, triple row et cetera - if indivisible will pad with black blank rows = 3 #@param {type: 'integer'} cols = math.ceil((len(images)/rows)) grid = image_grid(images, rows=rows, cols=cols) -
twobob revised this gist
Aug 23, 2022 . 1 changed file with 26 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,56 +1,57 @@ from PIL import Image from PIL import ImageFont from PIL import ImageDraw import math #Self contain this for easy single clicking from PIL import Image def image_grid(imgs, rows, cols): #assert len(imgs) == rows*cols w, h = imgs[0].size grid = Image.new('RGB', size=(cols*w, rows*h)) grid_w, grid_h = grid.size for i, img in enumerate(imgs): grid.paste(img, box=(i%cols*w, i//cols*h)) return grid # grab the font !test -f "/content/SansSerif.ttf" && echo "Skipping download" || wget -nc "https://github.com/PrincetonUniversity/COS333_Comet/blob/master/android/app/src/main/assets/fonts/Microsoft%20Sans%20Serif.ttf?raw=true" !test -f "/content/Microsoft Sans Serif.ttf?raw=true" && mv "/content/Microsoft Sans Serif.ttf?raw=true" "/content/SansSerif.ttf" font = ImageFont.truetype("/content/SansSerif.ttf", 120) # add a couple of options # can be any whole number above 0 manual_seed = 1024 #@param {type: 'integer'} # make it divisible by your column count and your row count image_count = 3 #@param {type: 'integer'} # how may we add each time we do a new image step_increase = 7 #@param {type: 'integer'} # jump over the first few steps to avoid NSFW flag NSFW_skip_start_step = 5 #@param {type: 'integer'} height = 640 #@param {type: 'integer'} width = 832 #@param {type: 'integer'} guidance_scale =8 #@param {type: 'integer'} # we are ready to prompt. images=[] prompt = "simple test aurora dramatic mountaintop, distant glowing figures" #@param {type: 'string'} # do the run current_steps = NSFW_skip_start_step for i in range(image_count): with autocast("cuda"): title = str(current_steps) generator = torch.Generator("cuda").manual_seed(manual_seed) img = pipe(prompt, generator=generator, height=height, width=width, num_inference_steps=current_steps, guidance_scale=guidance_scale )["sample"][0] draw = ImageDraw.Draw(img) draw.text((width/2, 50), title, (255,255,255),font=font) #img.save('/content/MyDrive/uniquename.jpg') TODO images.append(img) current_steps += step_increase #single, double, triple row et cetera - if indivisible will pad with black blank rows = 2 cols = math.ceil((len(images)/rows)) grid = image_grid(images, rows=rows, cols=cols) #now show it grid -
twobob revised this gist
Aug 23, 2022 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ #Self contain this for easy single clicking from PIL import Image def image_grid(imgs, rows, cols): assert len(imgs) == rows*cols w, h = imgs[0].size grid = Image.new('RGB', size=(cols*w, rows*h)) grid_w, grid_h = grid.size for i, img in enumerate(imgs): grid.paste(img, box=(i%cols*w, i//cols*h)) return grid # grab the font, here we use an online one for simplicity, you could just use any ttf !test -f "/content/SansSerif.ttf" && echo "Skipping download" || wget -nc "https://github.com/PrincetonUniversity/COS333_Comet/blob/master/android/app/src/main/assets/fonts/Microsoft%20Sans%20Serif.ttf?raw=true" -
twobob revised this gist
Aug 23, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -45,8 +45,8 @@ grid = image_grid(images, rows=rows, cols=cols) #double row et cetera - no error checking for divisibility #rows = 2 #cols = int(len(images)/rows) #grid = image_grid(images, rows=rows, cols=cols) #might as well assert len(images) == rows*cols -
twobob revised this gist
Aug 23, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ # grid.paste(img, box=(i%cols*w, i//cols*h)) # return grid # grab the font, here we use an online one for simplicity, you could just use any ttf !test -f "/content/SansSerif.ttf" && echo "Skipping download" || wget -nc "https://github.com/PrincetonUniversity/COS333_Comet/blob/master/android/app/src/main/assets/fonts/Microsoft%20Sans%20Serif.ttf?raw=true" !test -f "/content/Microsoft Sans Serif.ttf?raw=true" && mv "/content/Microsoft Sans Serif.ttf?raw=true" "/content/SansSerif.ttf" font = ImageFont.truetype("/content/SansSerif.ttf", 120) -
twobob revised this gist
Aug 23, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ generator = torch.Generator("cuda").manual_seed(man_seed) img = pipe(prompt, generator=generator, height=height, width=width, num_inference_steps=current_steps, guidance_scale=8 )["sample"][0] draw = ImageDraw.Draw(img) draw.text((width/2, 50), title, (255,255,255),font=font) #img.save('/content/MyDrive/uniquename.jpg') TODO images.append(img) current_steps += step_increase -
twobob revised this gist
Aug 23, 2022 . 1 changed file with 8 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,21 +9,20 @@ # grid.paste(img, box=(i%cols*w, i//cols*h)) # return grid # grab the font !test -f "/content/SansSerif.ttf" && echo "Skipping download" || wget -nc "https://github.com/PrincetonUniversity/COS333_Comet/blob/master/android/app/src/main/assets/fonts/Microsoft%20Sans%20Serif.ttf?raw=true" !test -f "/content/Microsoft Sans Serif.ttf?raw=true" && mv "/content/Microsoft Sans Serif.ttf?raw=true" "/content/SansSerif.ttf" font = ImageFont.truetype("/content/SansSerif.ttf", 120) # add a couple of options man_seed = 1024 # can be any whole number above 0 image_count = 8 # make it divisible by your column count and your row count step_increase = 5 # how may we add each time we do a new image NSFW_skip_start_step = 5 # jump over the first few steps to avoid NSFW flag height = 640 width = 832 # we are ready to prompt. images=[] prompt = "My awesome prompt,\ multiline,\ -
twobob revised this gist
Aug 23, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ # return grid # add a couple of options !test -f "/content/SansSerif.ttf" && echo "Skipping download" || wget -nc "https://github.com/PrincetonUniversity/COS333_Comet/blob/master/android/app/src/main/assets/fonts/Microsoft%20Sans%20Serif.ttf?raw=true" !test -f "/content/Microsoft Sans Serif.ttf?raw=true" && mv "/content/Microsoft Sans Serif.ttf?raw=true" "/content/SansSerif.ttf" font = ImageFont.truetype("/content/SansSerif.ttf", 120) man_seed = 25 -
twobob revised this gist
Aug 23, 2022 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,8 @@ # return grid # add a couple of options !wget -nc "https://github.com/PrincetonUniversity/COS333_Comet/blob/master/android/app/src/main/assets/fonts/Microsoft%20Sans%20Serif.ttf?raw=true" !test -f "/content/Microsoft Sans Serif.ttf?raw=true" && mv "/content/Microsoft Sans Serif.ttf?raw=true" "/content/SansSerif.ttf" font = ImageFont.truetype("/content/SansSerif.ttf", 120) man_seed = 25 image_count = 8 -
twobob created this gist
Aug 23, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ #Self contain this for easy single clicking #from PIL import Image #def image_grid(imgs, rows, cols): # assert len(imgs) == rows*cols # w, h = imgs[0].size # grid = Image.new('RGB', size=(cols*w, rows*h)) # grid_w, grid_h = grid.size # for i, img in enumerate(imgs): # grid.paste(img, box=(i%cols*w, i//cols*h)) # return grid # add a couple of options font = ImageFont.truetype("/content/SansSerif.ttf", 120) man_seed = 25 image_count = 8 step_increase = 5 NSFW_skip_start_step = 5 height = 640 width = 832 # once we are ready to prompt. from PIL import Image from PIL import ImageFont from PIL import ImageDraw images=[] prompt = "My awesome prompt,\ multiline,\ sharp focus" current_steps = NSFW_skip_start_step for i in range(image_count): with autocast("cuda"): title = str(current_steps) generator = torch.Generator("cuda").manual_seed(man_seed) img = pipe(prompt, generator=generator, height=height, width=width, num_inference_steps=current_steps, guidance_scale=8 )["sample"][0] draw = ImageDraw.Draw(img) draw.text((400, 50), title, (255,255,255),font=font) #img.save('/content/MyDrive/uniquename.jpg') TODO images.append(img) current_steps += step_increase #single row rows = 1 cols = len(images) grid = image_grid(images, rows=rows, cols=cols) #double row et cetera - no error checking for divisibility # rows = 2 # cols = int(len(images)/rows) #grid = image_grid(images, rows=rows, cols=cols) #might as well assert len(images) == rows*cols #now show it grid