buttons class test
Browse files
app.py
CHANGED
|
@@ -37,6 +37,42 @@ df = Client("huggingface-projects/IF", DFIF_TOKEN)
|
|
| 37 |
#stable diffusion upscaler
|
| 38 |
sdlu = Client("huggingface-projects/stable-diffusion-latent-upscaler", DFIF_TOKEN)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Set up discord bot
|
| 41 |
class MyClient(discord.Client):
|
| 42 |
async def on_ready(self):
|
|
@@ -141,37 +177,29 @@ class MyClient(discord.Client):
|
|
| 141 |
combined_image_path = os.path.join(stage_1_results, 'combined_image.png')
|
| 142 |
combined_image.save(combined_image_path)
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
custom_timesteps_2 = 'smart50'
|
| 168 |
-
number_of_inference_steps_2 = 50
|
| 169 |
-
result_path = df.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')
|
| 170 |
-
|
| 171 |
-
# Send the upscaled image in a new message
|
| 172 |
-
upscale_image_path = os.path.join(result_path, "output.png")
|
| 173 |
-
with open(upscale_image_path, 'rb') as f:
|
| 174 |
-
await interaction.channel.send('Here is the upscaled image:', file=discord.File(f, 'upscaled_image.png'))
|
| 175 |
|
| 176 |
|
| 177 |
DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
|
|
|
|
| 37 |
#stable diffusion upscaler
|
| 38 |
sdlu = Client("huggingface-projects/stable-diffusion-latent-upscaler", DFIF_TOKEN)
|
| 39 |
|
| 40 |
+
#---------------------------------------------------------------------------------------------------------------------------------------------------
|
| 41 |
+
class ButtonView(discord.ui.View):
|
| 42 |
+
def __init__(self, ctx, image_paths, stage_1_result_path):
|
| 43 |
+
super().__init__()
|
| 44 |
+
self.ctx = ctx
|
| 45 |
+
self.image_paths = image_paths
|
| 46 |
+
self.stage_1_result_path = stage_1_result_path
|
| 47 |
+
|
| 48 |
+
async def on_timeout(self):
|
| 49 |
+
for child in self.children:
|
| 50 |
+
child.disabled = True
|
| 51 |
+
self.stop()
|
| 52 |
+
|
| 53 |
+
@discord.ui.button(label='Image 1', style=discord.ButtonStyle.blurple)
|
| 54 |
+
async def image1_button(self, button: discord.ui.Button, interaction: discord.Interaction):
|
| 55 |
+
await self.ctx.invoke(self.ctx.bot.get_command('dfif2'), image_path=self.image_paths[0], stage_1_result_path=self.stage_1_result_path)
|
| 56 |
+
self.stop()
|
| 57 |
+
|
| 58 |
+
@discord.ui.button(label='Image 2', style=discord.ButtonStyle.blurple)
|
| 59 |
+
async def image2_button(self, button: discord.ui.Button, interaction: discord.Interaction):
|
| 60 |
+
await self.ctx.invoke(self.ctx.bot.get_command('dfif2'), image_path=self.image_paths[1], stage_1_result_path=self.stage_1_result_path)
|
| 61 |
+
self.stop()
|
| 62 |
+
|
| 63 |
+
@discord.ui.button(label='Image 3', style=discord.ButtonStyle.blurple)
|
| 64 |
+
async def image3_button(self, button: discord.ui.Button, interaction: discord.Interaction):
|
| 65 |
+
await self.ctx.invoke(self.ctx.bot.get_command('dfif2'), image_path=self.image_paths[2], stage_1_result_path=self.stage_1_result_path)
|
| 66 |
+
self.stop()
|
| 67 |
+
|
| 68 |
+
@discord.ui.button(label='Image 4', style=discord.ButtonStyle.blurple)
|
| 69 |
+
async def image4_button(self, button: discord.ui.Button, interaction: discord.Interaction):
|
| 70 |
+
await self.ctx.invoke(self.ctx.bot.get_command('dfif2'), image_path=self.image_paths[3], stage_1_result_path=self.stage_1_result_path)
|
| 71 |
+
self.stop()
|
| 72 |
+
#---------------------------------------------------------------------------------------------------------------------------------------------------
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
#---------------------------------------------------------------------------------------------------------------------------------------------------
|
| 76 |
# Set up discord bot
|
| 77 |
class MyClient(discord.Client):
|
| 78 |
async def on_ready(self):
|
|
|
|
| 177 |
combined_image_path = os.path.join(stage_1_results, 'combined_image.png')
|
| 178 |
combined_image.save(combined_image_path)
|
| 179 |
|
| 180 |
+
|
| 181 |
+
# Send the combined image file as a discord attachment with the button view
|
| 182 |
+
with open(combined_image_path, 'rb') as f:
|
| 183 |
+
view = ButtonView(message, [first_png_path, second_png_path, third_png_path, fourth_png_path], stage_1_result_path)
|
| 184 |
+
await message.reply('Here is the combined image', file=discord.File(f, 'combined_image.png'), view=view)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
#stage 2, can be stable diffusion too---------------------------------------------------------------------------------------------------------------------------------------------------
|
| 190 |
+
async def dfif2(self, ctx, image_path, stage_1_result_path):
|
| 191 |
+
selected_index_for_stage_2 = 0
|
| 192 |
+
seed_2 = 0
|
| 193 |
+
guidance_scale_2 = 4
|
| 194 |
+
custom_timesteps_2 = 'smart50'
|
| 195 |
+
number_of_inference_steps_2 = 50
|
| 196 |
+
result_path = df.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')
|
| 197 |
+
|
| 198 |
+
with open(result_path, 'rb') as f:
|
| 199 |
+
await ctx.reply('Here is the result of the second stage', file=discord.File(f, 'result.png'))
|
| 200 |
+
|
| 201 |
+
#---------------------------------------------------------------------------------------------------------------------------------------------------
|
| 202 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
|
| 205 |
DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
|