lunarflu HF Staff commited on
Commit
d3b6268
·
1 Parent(s): 8eadb7c

Update deepfloydif.py

Browse files
Files changed (1) hide show
  1. deepfloydif.py +48 -50
deepfloydif.py CHANGED
@@ -37,6 +37,26 @@ def deepfloydif_stage_2_inference(index, stage_1_result_path):
37
  result_path = deepfloydif_client.predict(stage_1_result_path, selected_index_for_stage_2, seed_2, guidance_scale_2, custom_timesteps_2, number_of_inference_steps_2, api_name='/upscale256')
38
  return result_path
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  async def deepfloydif_stage_1(interaction, prompt, client):
42
  """DeepfloydIF command (generate images with realistic text using slash commands)"""
@@ -89,55 +109,6 @@ async def deepfloydif_stage_1(interaction, prompt, client):
89
 
90
  except Exception as e:
91
  print(f"Error: {e}")
92
-
93
- def load_image(png_files, stage_1_results, png_file_index):
94
- """Opens images as variables so we can combine them later"""
95
- for file in png_files:
96
- png_file = png_files[png_file_index]
97
- png_path = os.path.join(stage_1_results, png_file)
98
- if png_file_index == 0:
99
- img1 = Image.open(png_path)
100
- if png_file_index == 1:
101
- img2 = Image.open(png_path)
102
- if png_file_index == 2:
103
- img3 = Image.open(png_path)
104
- if png_file_index == 3:
105
- img4 = Image.open(png_path)
106
- png_file_index = png_file_index + 1
107
- return [img1, img2, img3, img4]
108
-
109
- async def react_1234(reaction_emojis, combined_image_dfif):
110
- """Sets up 4 reaction emojis so the user can choose an image to upscale for deepfloydif"""
111
- for emoji in reaction_emojis:
112
- await combined_image_dfif.add_reaction(emoji)
113
-
114
- async def deepfloydif_stage_2(index: int, stage_1_result_path, thread, dfif_command_message_id):
115
- """upscaling function for images generated using /deepfloydif"""
116
- try:
117
- if os.environ.get('TEST_ENV') == 'True':
118
- print("Running deepfloydif_stage_2")
119
- parent_channel = thread.parent
120
- dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
121
- if index == 0:
122
- position = "top left"
123
- elif index == 1:
124
- position = "top right"
125
- elif index == 2:
126
- position = "bottom left"
127
- elif index == 3:
128
- position = "bottom right"
129
- await thread.send(f"Upscaling the {position} image...")
130
-
131
- # run blocking function in executor
132
- loop = asyncio.get_running_loop()
133
- result_path = await loop.run_in_executor(None, deepfloydif_stage_2_inference, index, stage_1_result_path)
134
-
135
- with open(result_path, 'rb') as f:
136
- await thread.send('Here is the upscaled image!', file=discord.File(f, 'result.png'))
137
- await thread.edit(archived=True)
138
-
139
- except Exception as e:
140
- print(f"Error: {e}")
141
 
142
  async def deepfloydif_stage_2_react_check(reaction, user):
143
  """Checks for a reaction in order to call dfif2"""
@@ -173,4 +144,31 @@ async def deepfloydif_stage_2_react_check(reaction, user):
173
 
174
  except Exception as e:
175
  print(f"Error: {e} (known error, does not cause issues, low priority)")
176
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  result_path = deepfloydif_client.predict(stage_1_result_path, selected_index_for_stage_2, seed_2, guidance_scale_2, custom_timesteps_2, number_of_inference_steps_2, api_name='/upscale256')
38
  return result_path
39
 
40
+ async def react_1234(reaction_emojis, combined_image_dfif):
41
+ """Sets up 4 reaction emojis so the user can choose an image to upscale for deepfloydif"""
42
+ for emoji in reaction_emojis:
43
+ await combined_image_dfif.add_reaction(emoji)
44
+
45
+ def load_image(png_files, stage_1_results, png_file_index):
46
+ """Opens images as variables so we can combine them later"""
47
+ for file in png_files:
48
+ png_file = png_files[png_file_index]
49
+ png_path = os.path.join(stage_1_results, png_file)
50
+ if png_file_index == 0:
51
+ img1 = Image.open(png_path)
52
+ if png_file_index == 1:
53
+ img2 = Image.open(png_path)
54
+ if png_file_index == 2:
55
+ img3 = Image.open(png_path)
56
+ if png_file_index == 3:
57
+ img4 = Image.open(png_path)
58
+ png_file_index = png_file_index + 1
59
+ return [img1, img2, img3, img4]
60
 
61
  async def deepfloydif_stage_1(interaction, prompt, client):
62
  """DeepfloydIF command (generate images with realistic text using slash commands)"""
 
109
 
110
  except Exception as e:
111
  print(f"Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
  async def deepfloydif_stage_2_react_check(reaction, user):
114
  """Checks for a reaction in order to call dfif2"""
 
144
 
145
  except Exception as e:
146
  print(f"Error: {e} (known error, does not cause issues, low priority)")
147
+
148
+ async def deepfloydif_stage_2(index: int, stage_1_result_path, thread, dfif_command_message_id):
149
+ """upscaling function for images generated using /deepfloydif"""
150
+ try:
151
+ if os.environ.get('TEST_ENV') == 'True':
152
+ print("Running deepfloydif_stage_2")
153
+ parent_channel = thread.parent
154
+ dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
155
+ if index == 0:
156
+ position = "top left"
157
+ elif index == 1:
158
+ position = "top right"
159
+ elif index == 2:
160
+ position = "bottom left"
161
+ elif index == 3:
162
+ position = "bottom right"
163
+ await thread.send(f"Upscaling the {position} image...")
164
+
165
+ # run blocking function in executor
166
+ loop = asyncio.get_running_loop()
167
+ result_path = await loop.run_in_executor(None, deepfloydif_stage_2_inference, index, stage_1_result_path)
168
+
169
+ with open(result_path, 'rb') as f:
170
+ await thread.send('Here is the upscaled image!', file=discord.File(f, 'result.png'))
171
+ await thread.edit(archived=True)
172
+
173
+ except Exception as e:
174
+ print(f"Error: {e}")