[deepfloydif.py] cleanup
Browse files- deepfloydif.py +3 -33
deepfloydif.py
CHANGED
@@ -3,7 +3,6 @@ from discord import app_commands
|
|
3 |
import gradio as gr
|
4 |
from gradio_client import Client
|
5 |
import os
|
6 |
-
import threading
|
7 |
import json
|
8 |
import random
|
9 |
from PIL import Image
|
@@ -12,12 +11,10 @@ import glob
|
|
12 |
import pathlib
|
13 |
|
14 |
HF_TOKEN = os.getenv('HF_TOKEN')
|
15 |
-
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
16 |
deepfloyd_client = Client("huggingface-projects/IF", HF_TOKEN)
|
17 |
|
18 |
-
BOT_USER_ID = 1086256910572986469
|
19 |
-
DEEPFLOYD_CHANNEL_ID = 1121834257959092234
|
20 |
-
|
21 |
|
22 |
def deepfloyd_stage_1_inference(prompt):
|
23 |
"""Generates an image based on a prompt"""
|
@@ -27,9 +24,7 @@ def deepfloyd_stage_1_inference(prompt):
|
|
27 |
guidance_scale = 7
|
28 |
custom_timesteps_1 = 'smart50'
|
29 |
number_of_inference_steps = 50
|
30 |
-
|
31 |
stage_1_results, stage_1_param_path, stage_1_result_path = deepfloyd_client.predict(prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name='/generate64')
|
32 |
-
|
33 |
return [stage_1_results, stage_1_param_path, stage_1_result_path]
|
34 |
|
35 |
def deepfloyd_stage_2_inference(index, stage_1_result_path):
|
@@ -44,7 +39,6 @@ def deepfloyd_stage_2_inference(index, stage_1_result_path):
|
|
44 |
|
45 |
async def deepfloydif_stage_1(interaction, prompt, client):
|
46 |
"""DeepfloydIF command (generate images with realistic text using slash commands)"""
|
47 |
-
thread = None
|
48 |
try:
|
49 |
global BOT_USER_ID
|
50 |
global DEEPFLOYD_CHANNEL_ID
|
@@ -54,12 +48,9 @@ async def deepfloydif_stage_1(interaction, prompt, client):
|
|
54 |
channel = interaction.channel
|
55 |
# interaction.response message can't be used to create a thread, so we create another message
|
56 |
message = await channel.send("DeepfloydIF Thread")
|
57 |
-
#await message.add_reaction('<a:loading:1114111677990981692>')
|
58 |
thread = await message.create_thread(name=f'{prompt}', auto_archive_duration=60)
|
59 |
await thread.send("[DISCLAIMER: HuggingBot is a **highly experimental** beta feature; Additional information on the DeepfloydIF model can be found here: https://huggingface.co/spaces/DeepFloyd/IF")
|
60 |
-
|
61 |
dfif_command_message_id = message.id # used for updating the 'status' of our generations using reaction emojis
|
62 |
-
|
63 |
await thread.send(f'{interaction.user.mention} Generating images in thread, can take ~1 minute...')
|
64 |
|
65 |
loop = asyncio.get_running_loop()
|
@@ -86,8 +77,6 @@ async def deepfloydif_stage_1(interaction, prompt, client):
|
|
86 |
|
87 |
emoji_list = ['↖️', '↗️', '↙️', '↘️']
|
88 |
await react_1234(emoji_list, combined_image_dfif)
|
89 |
-
#await message.remove_reaction('<a:loading:1114111677990981692>', client.user)
|
90 |
-
#await message.add_reaction('<:agree:1098629085955113011>')
|
91 |
else:
|
92 |
await thread.send(f'{interaction.user.mention} No PNG files were found, cannot post them!')
|
93 |
|
@@ -120,8 +109,6 @@ async def deepfloydif_stage_2(index: int, stage_1_result_path, thread, dfif_comm
|
|
120 |
try:
|
121 |
parent_channel = thread.parent
|
122 |
dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
|
123 |
-
#await dfif_command_message.remove_reaction('<:agree:1098629085955113011>', client.user)
|
124 |
-
#await dfif_command_message.add_reaction('<a:loading:1114111677990981692>')
|
125 |
if index == 0:
|
126 |
position = "top left"
|
127 |
elif index == 1:
|
@@ -138,34 +125,17 @@ async def deepfloydif_stage_2(index: int, stage_1_result_path, thread, dfif_comm
|
|
138 |
|
139 |
with open(result_path, 'rb') as f:
|
140 |
await thread.send('Here is the upscaled image!', file=discord.File(f, 'result.png'))
|
141 |
-
|
142 |
-
#await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', client.user)
|
143 |
-
#await dfif_command_message.add_reaction('<:agree:1098629085955113011>')
|
144 |
await thread.edit(archived=True)
|
145 |
|
146 |
except Exception as e:
|
147 |
print(f"Error: {e}")
|
148 |
-
parent_channel = thread.parent
|
149 |
-
dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
|
150 |
-
#await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', client.user)
|
151 |
-
#await dfif_command_message.add_reaction('<:disagree:1098628957521313892>')
|
152 |
-
await thread.send(f"Error during stage 2 upscaling, {e}")
|
153 |
-
await thread.edit(archived=True)
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
|
163 |
async def deepfloydif_stage_2_react_check(reaction, user):
|
164 |
"""Checks for a reaction in order to call dfif2"""
|
165 |
try:
|
166 |
global BOT_USER_ID
|
167 |
global DEEPFLOYD_CHANNEL_ID
|
168 |
-
if user.id != BOT_USER_ID:
|
169 |
thread = reaction.message.channel
|
170 |
thread_parent_id = thread.parent.id
|
171 |
if thread_parent_id == DEEPFLOYD_CHANNEL_ID:
|
|
|
3 |
import gradio as gr
|
4 |
from gradio_client import Client
|
5 |
import os
|
|
|
6 |
import json
|
7 |
import random
|
8 |
from PIL import Image
|
|
|
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"""
|
|
|
24 |
guidance_scale = 7
|
25 |
custom_timesteps_1 = 'smart50'
|
26 |
number_of_inference_steps = 50
|
|
|
27 |
stage_1_results, stage_1_param_path, stage_1_result_path = deepfloyd_client.predict(prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name='/generate64')
|
|
|
28 |
return [stage_1_results, stage_1_param_path, stage_1_result_path]
|
29 |
|
30 |
def deepfloyd_stage_2_inference(index, stage_1_result_path):
|
|
|
39 |
|
40 |
async def deepfloydif_stage_1(interaction, prompt, client):
|
41 |
"""DeepfloydIF command (generate images with realistic text using slash commands)"""
|
|
|
42 |
try:
|
43 |
global BOT_USER_ID
|
44 |
global DEEPFLOYD_CHANNEL_ID
|
|
|
48 |
channel = interaction.channel
|
49 |
# interaction.response message can't be used to create a thread, so we create another message
|
50 |
message = await channel.send("DeepfloydIF Thread")
|
|
|
51 |
thread = await message.create_thread(name=f'{prompt}', auto_archive_duration=60)
|
52 |
await thread.send("[DISCLAIMER: HuggingBot is a **highly experimental** beta feature; Additional information on the DeepfloydIF model can be found here: https://huggingface.co/spaces/DeepFloyd/IF")
|
|
|
53 |
dfif_command_message_id = message.id # used for updating the 'status' of our generations using reaction emojis
|
|
|
54 |
await thread.send(f'{interaction.user.mention} Generating images in thread, can take ~1 minute...')
|
55 |
|
56 |
loop = asyncio.get_running_loop()
|
|
|
77 |
|
78 |
emoji_list = ['↖️', '↗️', '↙️', '↘️']
|
79 |
await react_1234(emoji_list, combined_image_dfif)
|
|
|
|
|
80 |
else:
|
81 |
await thread.send(f'{interaction.user.mention} No PNG files were found, cannot post them!')
|
82 |
|
|
|
109 |
try:
|
110 |
parent_channel = thread.parent
|
111 |
dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
|
|
|
|
|
112 |
if index == 0:
|
113 |
position = "top left"
|
114 |
elif index == 1:
|
|
|
125 |
|
126 |
with open(result_path, 'rb') as f:
|
127 |
await thread.send('Here is the upscaled image!', file=discord.File(f, 'result.png'))
|
|
|
|
|
|
|
128 |
await thread.edit(archived=True)
|
129 |
|
130 |
except Exception as e:
|
131 |
print(f"Error: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
async def deepfloydif_stage_2_react_check(reaction, user):
|
134 |
"""Checks for a reaction in order to call dfif2"""
|
135 |
try:
|
136 |
global BOT_USER_ID
|
137 |
global DEEPFLOYD_CHANNEL_ID
|
138 |
+
if user.id != BOT_USER_ID:
|
139 |
thread = reaction.message.channel
|
140 |
thread_parent_id = thread.parent.id
|
141 |
if thread_parent_id == DEEPFLOYD_CHANNEL_ID:
|