lunarflu HF Staff commited on
Commit
1dc3613
·
1 Parent(s): 0637a63

[deepfloydif.py] made spelling consistent (deepfloydif, not deepfloyd)

Browse files
Files changed (1) hide show
  1. deepfloydif.py +12 -12
deepfloydif.py CHANGED
@@ -11,12 +11,12 @@ import glob
11
  import pathlib
12
 
13
  HF_TOKEN = os.getenv('HF_TOKEN')
14
- deepfloyd_client = Client("huggingface-projects/IF", HF_TOKEN)
15
 
16
  BOT_USER_ID = 1086256910572986469 if os.getenv("TEST_ENV", False) else 1102236653545861151
17
- DEEPFLOYD_CHANNEL_ID = 1121834257959092234 if os.getenv("TEST_ENV", False) else 1119313215675973714
18
 
19
- def deepfloyd_stage_1_inference(prompt):
20
  """Generates an image based on a prompt"""
21
  negative_prompt = ''
22
  seed = random.randint(0, 1000)
@@ -34,23 +34,23 @@ def deepfloyd_stage_1_inference(prompt):
34
  stage_1_result_path = result[2]
35
  return [stage_1_results, stage_1_result_path]
36
 
37
- def deepfloyd_stage_2_inference(index, stage_1_result_path):
38
- """Upscales one of the images from deepfloyd_stage_1_inference based on the chosen index"""
39
  selected_index_for_stage_2 = index
40
  seed_2 = 0
41
  guidance_scale_2 = 4
42
  custom_timesteps_2 = 'smart50'
43
  number_of_inference_steps_2 = 50
44
- result_path = deepfloyd_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')
45
  return result_path
46
 
47
  async def deepfloydif_stage_1(interaction, prompt, client):
48
  """DeepfloydIF command (generate images with realistic text using slash commands)"""
49
  try:
50
  global BOT_USER_ID
51
- global DEEPFLOYD_CHANNEL_ID
52
  if interaction.user.id != BOT_USER_ID:
53
- if interaction.channel.id == DEEPFLOYD_CHANNEL_ID:
54
  await interaction.response.send_message("Working on it!")
55
  channel = interaction.channel
56
  # interaction.response message can't be used to create a thread, so we create another message
@@ -62,7 +62,7 @@ async def deepfloydif_stage_1(interaction, prompt, client):
62
 
63
  '''
64
  loop = asyncio.get_running_loop()
65
- result = await loop.run_in_executor(None, deepfloyd_stage_1_inference, prompt)
66
  stage_1_results = result[0]
67
  stage_1_result_path = result[2]
68
  '''
@@ -134,7 +134,7 @@ async def deepfloydif_stage_2(index: int, stage_1_result_path, thread, dfif_comm
134
 
135
  # run blocking function in executor
136
  loop = asyncio.get_running_loop()
137
- result_path = await loop.run_in_executor(None, deepfloyd_stage_2_inference, index, stage_1_result_path)
138
 
139
  with open(result_path, 'rb') as f:
140
  await thread.send('Here is the upscaled image!', file=discord.File(f, 'result.png'))
@@ -147,11 +147,11 @@ async def deepfloydif_stage_2_react_check(reaction, user):
147
  """Checks for a reaction in order to call dfif2"""
148
  try:
149
  global BOT_USER_ID
150
- global DEEPFLOYD_CHANNEL_ID
151
  if user.id != BOT_USER_ID:
152
  thread = reaction.message.channel
153
  thread_parent_id = thread.parent.id
154
- if thread_parent_id == DEEPFLOYD_CHANNEL_ID:
155
  if reaction.message.attachments:
156
  if user.id == reaction.message.mentions[0].id:
157
  attachment = reaction.message.attachments[0]
 
11
  import pathlib
12
 
13
  HF_TOKEN = os.getenv('HF_TOKEN')
14
+ deepfloydif_client = Client("huggingface-projects/IF", HF_TOKEN)
15
 
16
  BOT_USER_ID = 1086256910572986469 if os.getenv("TEST_ENV", False) else 1102236653545861151
17
+ DEEPFLOYDIF_CHANNEL_ID = 1121834257959092234 if os.getenv("TEST_ENV", False) else 1119313215675973714
18
 
19
+ def deepfloydif_stage_1_inference(prompt):
20
  """Generates an image based on a prompt"""
21
  negative_prompt = ''
22
  seed = random.randint(0, 1000)
 
34
  stage_1_result_path = result[2]
35
  return [stage_1_results, stage_1_result_path]
36
 
37
+ def deepfloydif_stage_2_inference(index, stage_1_result_path):
38
+ """Upscales one of the images from deepfloydif_stage_1_inference based on the chosen index"""
39
  selected_index_for_stage_2 = index
40
  seed_2 = 0
41
  guidance_scale_2 = 4
42
  custom_timesteps_2 = 'smart50'
43
  number_of_inference_steps_2 = 50
44
+ 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')
45
  return result_path
46
 
47
  async def deepfloydif_stage_1(interaction, prompt, client):
48
  """DeepfloydIF command (generate images with realistic text using slash commands)"""
49
  try:
50
  global BOT_USER_ID
51
+ global DEEPFLOYDIF_CHANNEL_ID
52
  if interaction.user.id != BOT_USER_ID:
53
+ if interaction.channel.id == DEEPFLOYDIF_CHANNEL_ID:
54
  await interaction.response.send_message("Working on it!")
55
  channel = interaction.channel
56
  # interaction.response message can't be used to create a thread, so we create another message
 
62
 
63
  '''
64
  loop = asyncio.get_running_loop()
65
+ result = await loop.run_in_executor(None, deepfloydif_stage_1_inference, prompt)
66
  stage_1_results = result[0]
67
  stage_1_result_path = result[2]
68
  '''
 
134
 
135
  # run blocking function in executor
136
  loop = asyncio.get_running_loop()
137
+ result_path = await loop.run_in_executor(None, deepfloydif_stage_2_inference, index, stage_1_result_path)
138
 
139
  with open(result_path, 'rb') as f:
140
  await thread.send('Here is the upscaled image!', file=discord.File(f, 'result.png'))
 
147
  """Checks for a reaction in order to call dfif2"""
148
  try:
149
  global BOT_USER_ID
150
+ global DEEPFLOYDIF_CHANNEL_ID
151
  if user.id != BOT_USER_ID:
152
  thread = reaction.message.channel
153
  thread_parent_id = thread.parent.id
154
+ if thread_parent_id == DEEPFLOYDIF_CHANNEL_ID:
155
  if reaction.message.attachments:
156
  if user.id == reaction.message.mentions[0].id:
157
  attachment = reaction.message.attachments[0]