[deepfloydif.py] shifting job.submit back outside to dfif_stage_1_inference function
Browse files- deepfloydif.py +25 -42
deepfloydif.py
CHANGED
|
@@ -30,6 +30,7 @@ async def deepfloydif_stage_1_inference(prompt):
|
|
| 30 |
pass
|
| 31 |
else:
|
| 32 |
file_paths = job.outputs()
|
|
|
|
| 33 |
return file_paths
|
| 34 |
|
| 35 |
def deepfloydif_stage_2_inference(index, stage_1_result_path):
|
|
@@ -59,50 +60,32 @@ async def deepfloydif_stage_1(interaction, prompt, client):
|
|
| 59 |
dfif_command_message_id = message.id # used for updating the 'status' of our generations using reaction emojis
|
| 60 |
await thread.send(f'{interaction.user.mention} Generating images in thread, can take ~1 minute...')
|
| 61 |
|
| 62 |
-
|
| 63 |
-
loop = asyncio.get_running_loop()
|
| 64 |
-
result = await loop.run_in_executor(None, deepfloydif_stage_1_inference, prompt)
|
| 65 |
-
stage_1_results = result[0]
|
| 66 |
-
stage_1_result_path = result[2]
|
| 67 |
-
'''
|
| 68 |
-
negative_prompt = ''
|
| 69 |
-
seed = random.randint(0, 1000)
|
| 70 |
-
number_of_images = 4
|
| 71 |
-
guidance_scale = 7
|
| 72 |
-
custom_timesteps_1 = 'smart50'
|
| 73 |
-
number_of_inference_steps = 50
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
file_paths = job.outputs()
|
| 80 |
-
file_paths = file_paths[0]
|
| 81 |
-
stage_1_results = file_paths[0]
|
| 82 |
-
stage_1_result_path = file_paths[2]
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
await react_1234(emoji_list, combined_image_dfif)
|
| 104 |
-
else:
|
| 105 |
-
await thread.send(f'{interaction.user.mention} No PNG files were found, cannot post them!')
|
| 106 |
|
| 107 |
except Exception as e:
|
| 108 |
print(f"Error: {e}")
|
|
|
|
| 30 |
pass
|
| 31 |
else:
|
| 32 |
file_paths = job.outputs()
|
| 33 |
+
file_paths = file_paths[0]
|
| 34 |
return file_paths
|
| 35 |
|
| 36 |
def deepfloydif_stage_2_inference(index, stage_1_result_path):
|
|
|
|
| 60 |
dfif_command_message_id = message.id # used for updating the 'status' of our generations using reaction emojis
|
| 61 |
await thread.send(f'{interaction.user.mention} Generating images in thread, can take ~1 minute...')
|
| 62 |
|
| 63 |
+
file_paths = await deepfloydif_stage_1_inference(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
stage_1_results = file_paths[0]
|
| 66 |
+
stage_1_result_path = file_paths[2]
|
| 67 |
+
partial_path = pathlib.Path(stage_1_result_path).name
|
| 68 |
+
png_files = list(glob.glob(f"{stage_1_results}/**/*.png"))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
if png_files:
|
| 71 |
+
# take all 4 images and combine them into one large 2x2 image (similar to Midjourney)
|
| 72 |
+
png_file_index = 0
|
| 73 |
+
images = load_image(png_files, stage_1_results, png_file_index)
|
| 74 |
+
combined_image = Image.new('RGB', (images[0].width * 2, images[0].height * 2))
|
| 75 |
+
combined_image.paste(images[0], (0, 0))
|
| 76 |
+
combined_image.paste(images[1], (images[0].width, 0))
|
| 77 |
+
combined_image.paste(images[2], (0, images[0].height))
|
| 78 |
+
combined_image.paste(images[3], (images[0].width, images[0].height))
|
| 79 |
+
combined_image_path = os.path.join(stage_1_results, f'{partial_path}{dfif_command_message_id}.png')
|
| 80 |
+
combined_image.save(combined_image_path)
|
| 81 |
+
|
| 82 |
+
with open(combined_image_path, 'rb') as f:
|
| 83 |
+
combined_image_dfif = await thread.send(f'{interaction.user.mention} React with the image number you want to upscale!', file=discord.File(f, f'{partial_path}{dfif_command_message_id}.png'))
|
| 84 |
+
|
| 85 |
+
emoji_list = ['↖️', '↗️', '↙️', '↘️']
|
| 86 |
+
await react_1234(emoji_list, combined_image_dfif)
|
| 87 |
+
else:
|
| 88 |
+
await thread.send(f'{interaction.user.mention} No PNG files were found, cannot post them!')
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
except Exception as e:
|
| 91 |
print(f"Error: {e}")
|