Update app.py
Browse files
app.py
CHANGED
@@ -214,56 +214,69 @@ async def dfif(interaction: discord.Interaction, prompt: str):
|
|
214 |
await thread.send(f'{interaction.user.mention}Generating images in thread, can take ~1 minute...')
|
215 |
|
216 |
# generation
|
|
|
|
|
217 |
job = df.submit(prompt, negative_prompt, seed, number_of_images, guidance_scale,
|
218 |
custom_timesteps_1, number_of_inference_steps, api_name='/generate64')
|
219 |
while not job.done():
|
220 |
time.sleep(0.1)
|
221 |
-
else:
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
file_paths = file_paths[0] # tmp12345678.json
|
224 |
stage_1_results = file_paths[0]
|
225 |
stage_1_result_path = file_paths[2]
|
226 |
partialpath = stage_1_result_path[5:]
|
227 |
|
228 |
-
png_files = list(glob.glob(f"{stage_1_results}/**/*.png"))
|
|
|
229 |
|
230 |
-
if png_files:
|
231 |
-
first_png = png_files[0]
|
232 |
-
second_png = png_files[1]
|
233 |
-
third_png = png_files[2]
|
234 |
-
fourth_png = png_files[3]
|
235 |
-
|
236 |
-
first_png_path = os.path.join(stage_1_results, first_png)
|
237 |
-
second_png_path = os.path.join(stage_1_results, second_png)
|
238 |
-
third_png_path = os.path.join(stage_1_results, third_png)
|
239 |
-
fourth_png_path = os.path.join(stage_1_results, fourth_png)
|
240 |
-
|
241 |
-
img1 = Image.open(first_png_path)
|
242 |
-
img2 = Image.open(second_png_path)
|
243 |
-
img3 = Image.open(third_png_path)
|
244 |
-
img4 = Image.open(fourth_png_path)
|
245 |
-
|
246 |
-
combined_image = Image.new('RGB', (img1.width * 2, img1.height * 2))
|
247 |
-
|
248 |
-
combined_image.paste(img1, (0, 0))
|
249 |
-
combined_image.paste(img2, (img1.width, 0))
|
250 |
-
combined_image.paste(img3, (0, img1.height))
|
251 |
-
combined_image.paste(img4, (img1.width, img1.height))
|
252 |
-
|
253 |
-
combined_image_path = os.path.join(stage_1_results, f'{partialpath}{dfif_command_message_id}.png')
|
254 |
-
combined_image.save(combined_image_path)
|
255 |
|
256 |
-
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
|
265 |
-
|
266 |
-
|
|
|
267 |
|
268 |
|
269 |
|
|
|
214 |
await thread.send(f'{interaction.user.mention}Generating images in thread, can take ~1 minute...')
|
215 |
|
216 |
# generation
|
217 |
+
|
218 |
+
'''
|
219 |
job = df.submit(prompt, negative_prompt, seed, number_of_images, guidance_scale,
|
220 |
custom_timesteps_1, number_of_inference_steps, api_name='/generate64')
|
221 |
while not job.done():
|
222 |
time.sleep(0.1)
|
223 |
+
else:
|
224 |
+
'''
|
225 |
+
loop = asyncio.get_running_loop()
|
226 |
+
result = await loop.run_in_executor(None, inference, prompt)
|
227 |
+
stage_1_results = result[0]
|
228 |
+
stage_1_result_path = result[2]
|
229 |
+
partialpath = stage_1_result_path[5:]
|
230 |
+
png_files = list(glob.glob(f"{stage_1_results}/**/*.png"))
|
231 |
+
|
232 |
+
'''
|
233 |
+
file_paths = job.outputs()
|
234 |
file_paths = file_paths[0] # tmp12345678.json
|
235 |
stage_1_results = file_paths[0]
|
236 |
stage_1_result_path = file_paths[2]
|
237 |
partialpath = stage_1_result_path[5:]
|
238 |
|
239 |
+
png_files = list(glob.glob(f"{stage_1_results}/**/*.png"))
|
240 |
+
'''
|
241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
+
if png_files:
|
244 |
+
first_png = png_files[0]
|
245 |
+
second_png = png_files[1]
|
246 |
+
third_png = png_files[2]
|
247 |
+
fourth_png = png_files[3]
|
248 |
+
|
249 |
+
first_png_path = os.path.join(stage_1_results, first_png)
|
250 |
+
second_png_path = os.path.join(stage_1_results, second_png)
|
251 |
+
third_png_path = os.path.join(stage_1_results, third_png)
|
252 |
+
fourth_png_path = os.path.join(stage_1_results, fourth_png)
|
253 |
+
|
254 |
+
img1 = Image.open(first_png_path)
|
255 |
+
img2 = Image.open(second_png_path)
|
256 |
+
img3 = Image.open(third_png_path)
|
257 |
+
img4 = Image.open(fourth_png_path)
|
258 |
+
|
259 |
+
combined_image = Image.new('RGB', (img1.width * 2, img1.height * 2))
|
260 |
+
|
261 |
+
combined_image.paste(img1, (0, 0))
|
262 |
+
combined_image.paste(img2, (img1.width, 0))
|
263 |
+
combined_image.paste(img3, (0, img1.height))
|
264 |
+
combined_image.paste(img4, (img1.width, img1.height))
|
265 |
+
|
266 |
+
combined_image_path = os.path.join(stage_1_results, f'{partialpath}{dfif_command_message_id}.png')
|
267 |
+
combined_image.save(combined_image_path)
|
268 |
+
|
269 |
+
with open(combined_image_path, 'rb') as f:
|
270 |
+
combined_image_dfif = await thread.send(f'{interaction.user.mention}React with the image number you want to upscale!', file=discord.File(
|
271 |
+
f, f'{partialpath}{dfif_command_message_id}.png')) # named something like: tmpgtv4qjix1111269940599738479.png
|
272 |
|
273 |
|
274 |
+
emoji_list = ['↖️', '↗️', '↙️', '↘️']
|
275 |
+
await react1234(emoji_list, combined_image_dfif)
|
|
|
276 |
|
277 |
+
|
278 |
+
await message.remove_reaction('<a:loading:1121820108189339738>', client.user)
|
279 |
+
await message.add_reaction('✅')
|
280 |
|
281 |
|
282 |
|