lunarflu HF Staff commited on
Commit
43e9f1a
·
1 Parent(s): fb3bd09

[deepfloydif.py] added debugging

Browse files
Files changed (1) hide show
  1. deepfloydif.py +14 -0
deepfloydif.py CHANGED
@@ -60,6 +60,8 @@ async def deepfloydif_stage_1(interaction, prompt, client):
60
  global DEEPFLOYDIF_CHANNEL_ID
61
  if interaction.user.id != BOT_USER_ID:
62
  if interaction.channel.id == DEEPFLOYDIF_CHANNEL_ID:
 
 
63
  await interaction.response.send_message("Working on it!")
64
  channel = interaction.channel
65
  # interaction.response message can't be used to create a thread, so we create another message
@@ -82,10 +84,14 @@ async def deepfloydif_stage_1(interaction, prompt, client):
82
  custom_timesteps_1 = 'smart50'
83
  number_of_inference_steps = 50
84
 
 
 
85
  job = deepfloydif_client.submit(prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name='/generate64') # This is not blocking, similar to run_in_executor (but better)
86
  while job.done() is False:
87
  pass
88
  else:
 
 
89
  file_paths = job.outputs()
90
  file_paths = file_paths[0]
91
  stage_1_results = file_paths[0]
@@ -96,6 +102,8 @@ async def deepfloydif_stage_1(interaction, prompt, client):
96
 
97
  if png_files:
98
  # take all 4 images and combine them into one large 2x2 image (similar to Midjourney)
 
 
99
  png_file_index = 0
100
  images = load_image(png_files, stage_1_results, png_file_index)
101
  combined_image = Image.new('RGB', (images[0].width * 2, images[0].height * 2))
@@ -105,6 +113,8 @@ async def deepfloydif_stage_1(interaction, prompt, client):
105
  combined_image.paste(images[3], (images[0].width, images[0].height))
106
  combined_image_path = os.path.join(stage_1_results, f'{partial_path}{dfif_command_message_id}.png')
107
  combined_image.save(combined_image_path)
 
 
108
 
109
  with open(combined_image_path, 'rb') as f:
110
  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'))
@@ -141,6 +151,8 @@ async def react_1234(reaction_emojis, combined_image_dfif):
141
  async def deepfloydif_stage_2(index: int, stage_1_result_path, thread, dfif_command_message_id):
142
  """upscaling function for images generated using /deepfloydif"""
143
  try:
 
 
144
  parent_channel = thread.parent
145
  dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
146
  if index == 0:
@@ -167,6 +179,8 @@ async def deepfloydif_stage_2(index: int, stage_1_result_path, thread, dfif_comm
167
  async def deepfloydif_stage_2_react_check(reaction, user):
168
  """Checks for a reaction in order to call dfif2"""
169
  try:
 
 
170
  global BOT_USER_ID
171
  global DEEPFLOYDIF_CHANNEL_ID
172
  if user.id != BOT_USER_ID:
 
60
  global DEEPFLOYDIF_CHANNEL_ID
61
  if interaction.user.id != BOT_USER_ID:
62
  if interaction.channel.id == DEEPFLOYDIF_CHANNEL_ID:
63
+ if os.environ.get('TEST_ENV') == 'True':
64
+ print("Safetychecks passed for deepfloydif_stage_1")
65
  await interaction.response.send_message("Working on it!")
66
  channel = interaction.channel
67
  # interaction.response message can't be used to create a thread, so we create another message
 
84
  custom_timesteps_1 = 'smart50'
85
  number_of_inference_steps = 50
86
 
87
+ if os.environ.get('TEST_ENV') == 'True':
88
+ print("Running deepfloydif_client.submit")
89
  job = deepfloydif_client.submit(prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name='/generate64') # This is not blocking, similar to run_in_executor (but better)
90
  while job.done() is False:
91
  pass
92
  else:
93
+ if os.environ.get('TEST_ENV') == 'True':
94
+ print("Safetychecks passed for deepfloydif_stage_1")
95
  file_paths = job.outputs()
96
  file_paths = file_paths[0]
97
  stage_1_results = file_paths[0]
 
102
 
103
  if png_files:
104
  # take all 4 images and combine them into one large 2x2 image (similar to Midjourney)
105
+ if os.environ.get('TEST_ENV') == 'True':
106
+ print("Combining images for deepfloydif_stage_1")
107
  png_file_index = 0
108
  images = load_image(png_files, stage_1_results, png_file_index)
109
  combined_image = Image.new('RGB', (images[0].width * 2, images[0].height * 2))
 
113
  combined_image.paste(images[3], (images[0].width, images[0].height))
114
  combined_image_path = os.path.join(stage_1_results, f'{partial_path}{dfif_command_message_id}.png')
115
  combined_image.save(combined_image_path)
116
+ if os.environ.get('TEST_ENV') == 'True':
117
+ print("Images combined for deepfloydif_stage_1")
118
 
119
  with open(combined_image_path, 'rb') as f:
120
  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'))
 
151
  async def deepfloydif_stage_2(index: int, stage_1_result_path, thread, dfif_command_message_id):
152
  """upscaling function for images generated using /deepfloydif"""
153
  try:
154
+ if os.environ.get('TEST_ENV') == 'True':
155
+ print("Running deepfloydif_stage_2")
156
  parent_channel = thread.parent
157
  dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
158
  if index == 0:
 
179
  async def deepfloydif_stage_2_react_check(reaction, user):
180
  """Checks for a reaction in order to call dfif2"""
181
  try:
182
+ if os.environ.get('TEST_ENV') == 'True':
183
+ print("Running deepfloydif_stage_2_react_check")
184
  global BOT_USER_ID
185
  global DEEPFLOYDIF_CHANNEL_ID
186
  if user.id != BOT_USER_ID: