lunarflu HF Staff commited on
Commit
fd6e72f
·
1 Parent(s): 936985f

[dfif] testing fix for https://huggingface.co/spaces/DeepFloyd/IF/commit/fb79844b1d0b013a28ac435a36f804d8030fba50

Browse files
Files changed (1) hide show
  1. app.py +17 -21
app.py CHANGED
@@ -382,17 +382,13 @@ async def deepfloydif(ctx, *, prompt: str):
382
  # prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name='/generate64')
383
 
384
  # run blocking function in executor
385
- #await thread.send(f'✅running blocking function in executor')
386
- #loop = asyncio.get_running_loop()
387
- #result = await loop.run_in_executor(None, inference, prompt)
388
-
389
- stage_1_results, stage_1_param_path, stage_1_result_path = df.predict(
390
- prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name='/generate64')
391
-
392
  await thread.send(f'{ctx.author.mention}after executor')
393
  await thread.send(f'✅run_in_executor ran successfully')
394
- #stage_1_results = result[0]
395
- #stage_1_result_path = result[2]
396
 
397
  partialpath = stage_1_result_path[5:] #magic for later
398
 
@@ -408,10 +404,11 @@ async def deepfloydif(ctx, *, prompt: str):
408
  #posting images✅----------------------------------------------------------------
409
  try:
410
  await thread.send(f'✅combining images...')
411
- png_files = [f for f in os.listdir(stage_1_results) if f.endswith('.png')]
 
 
412
 
413
  if png_files:
414
- await thread.send('png files exists, combining images...')
415
  first_png = png_files[0]
416
  second_png = png_files[1]
417
  third_png = png_files[2]
@@ -421,27 +418,25 @@ async def deepfloydif(ctx, *, prompt: str):
421
  second_png_path = os.path.join(stage_1_results, second_png)
422
  third_png_path = os.path.join(stage_1_results, third_png)
423
  fourth_png_path = os.path.join(stage_1_results, fourth_png)
424
- await thread.send('defining images...')
425
  img1 = Image.open(first_png_path)
426
  img2 = Image.open(second_png_path)
427
  img3 = Image.open(third_png_path)
428
  img4 = Image.open(fourth_png_path)
429
 
430
  combined_image = Image.new('RGB', (img1.width * 2, img1.height * 2))
431
- await thread.send('pasting images...')
432
  combined_image.paste(img1, (0, 0))
433
  combined_image.paste(img2, (img1.width, 0))
434
  combined_image.paste(img3, (0, img1.height))
435
  combined_image.paste(img4, (img1.width, img1.height))
436
- await thread.send('saving combined image...')
437
  combined_image_path = os.path.join(stage_1_results, f'{partialpath}{dfif_command_message_id}.png')
438
  combined_image.save(combined_image_path)
439
- await thread.send('before posting combined image in thread...')
440
- with open(combined_image_path, 'rb') as f:
441
- combined_image_dfif = await thread.send(f'{ctx.author.mention}React with the image number you want to upscale!', file=discord.File(
442
- f, f'{partialpath}{dfif_command_message_id}.png')) # named something like: tmpgtv4qjix1111269940599738479.png
443
- elif not png_files:
444
- await thread.send('png files are empty.')
445
 
446
  await thread.send(f'✅reacting with 1234...')
447
  emoji_list = ['↖️', '↗️', '↙️', '↘️']
@@ -459,6 +454,7 @@ async def deepfloydif(ctx, *, prompt: str):
459
  await asyncio.sleep(1)
460
 
461
  '''
 
462
  except Exception as e:
463
  print(f"Error: {e}")
464
  if thread is None:
@@ -467,7 +463,7 @@ async def deepfloydif(ctx, *, prompt: str):
467
  await fullqueue(e, thread)
468
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
469
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
470
- await thread.edit(archived=True)
471
  #deepfloydif try/except
472
  except Exception as e:
473
  print(f"Error: {e}")
 
382
  # prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name='/generate64')
383
 
384
  # run blocking function in executor
385
+ await thread.send(f'✅running blocking function in executor')
386
+ loop = asyncio.get_running_loop()
387
+ result = await loop.run_in_executor(None, inference, prompt)
 
 
 
 
388
  await thread.send(f'{ctx.author.mention}after executor')
389
  await thread.send(f'✅run_in_executor ran successfully')
390
+ stage_1_results = result[0]
391
+ stage_1_result_path = result[2]
392
 
393
  partialpath = stage_1_result_path[5:] #magic for later
394
 
 
404
  #posting images✅----------------------------------------------------------------
405
  try:
406
  await thread.send(f'✅combining images...')
407
+ #old, see: https://huggingface.co/spaces/DeepFloyd/IF/commit/fb79844b1d0b013a28ac435a36f804d8030fba50
408
+ #png_files = [f for f in os.listdir(stage_1_results) if f.endswith('.png')]
409
+ png_files = list(glob.glob(f"{stage_1_results}/**/*.png"))
410
 
411
  if png_files:
 
412
  first_png = png_files[0]
413
  second_png = png_files[1]
414
  third_png = png_files[2]
 
418
  second_png_path = os.path.join(stage_1_results, second_png)
419
  third_png_path = os.path.join(stage_1_results, third_png)
420
  fourth_png_path = os.path.join(stage_1_results, fourth_png)
421
+
422
  img1 = Image.open(first_png_path)
423
  img2 = Image.open(second_png_path)
424
  img3 = Image.open(third_png_path)
425
  img4 = Image.open(fourth_png_path)
426
 
427
  combined_image = Image.new('RGB', (img1.width * 2, img1.height * 2))
428
+
429
  combined_image.paste(img1, (0, 0))
430
  combined_image.paste(img2, (img1.width, 0))
431
  combined_image.paste(img3, (0, img1.height))
432
  combined_image.paste(img4, (img1.width, img1.height))
433
+
434
  combined_image_path = os.path.join(stage_1_results, f'{partialpath}{dfif_command_message_id}.png')
435
  combined_image.save(combined_image_path)
436
+
437
+ with open(combined_image_path, 'rb') as f:
438
+ combined_image_dfif = await thread.send(f'{ctx.author.mention}React with the image number you want to upscale!', file=discord.File(
439
+ f, f'{partialpath}{dfif_command_message_id}.png')) # named something like: tmpgtv4qjix1111269940599738479.png
 
 
440
 
441
  await thread.send(f'✅reacting with 1234...')
442
  emoji_list = ['↖️', '↗️', '↙️', '↘️']
 
454
  await asyncio.sleep(1)
455
 
456
  '''
457
+
458
  except Exception as e:
459
  print(f"Error: {e}")
460
  if thread is None:
 
463
  await fullqueue(e, thread)
464
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
465
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
466
+ await thread.edit(archived=True)
467
  #deepfloydif try/except
468
  except Exception as e:
469
  print(f"Error: {e}")