[big revert] reverting to earlier version to pinpoint dfif issue
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import time
|
|
9 |
import re
|
10 |
from discord import Embed, Color
|
11 |
from discord.ext import commands
|
12 |
-
#
|
13 |
from gradio_client import Client
|
14 |
from PIL import Image
|
15 |
#from ratelimiter import RateLimiter
|
@@ -20,12 +20,6 @@ import multiprocessing
|
|
20 |
|
21 |
import shutil # for doing image movement magic
|
22 |
|
23 |
-
#import tempfile
|
24 |
-
#import glob
|
25 |
-
|
26 |
-
import uuid
|
27 |
-
|
28 |
-
|
29 |
#todo
|
30 |
# add safetychecks to all parts, test thoroughly
|
31 |
# add discord channels, configure for fellows
|
@@ -52,19 +46,14 @@ DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
|
|
52 |
|
53 |
df = Client("huggingface-projects/IF", GRADIOTEST_TOKEN)
|
54 |
jojogan = Client("akhaliq/JoJoGAN", GRADIOTEST_TOKEN)
|
55 |
-
|
56 |
|
57 |
intents = discord.Intents.default()
|
58 |
intents.message_content = True
|
59 |
|
60 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
61 |
|
62 |
-
|
63 |
-
@bot.command()
|
64 |
-
async def info(ctx):
|
65 |
-
current_directory = os.getcwd()
|
66 |
-
temp_directory = tempfile.gettempdir()
|
67 |
-
await ctx.reply(f"current_directory={current_directory}\n temp_directory={temp_directory}")
|
68 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
69 |
@bot.event
|
70 |
async def on_ready():
|
@@ -77,7 +66,7 @@ async def commands(ctx):
|
|
77 |
if await safetychecks(ctx):
|
78 |
await ctx.reply(f"Use !deepfloydif [prompt], !jojo !spidey or !sketch. Have fun! 🤗💖")
|
79 |
except Exception as e:
|
80 |
-
print(f"Error: unable to help :(
|
81 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
82 |
async def safetychecks(ctx):
|
83 |
failure_emoji = '<:disagree:1098628957521313892>'
|
@@ -99,13 +88,8 @@ async def safetychecks(ctx):
|
|
99 |
|
100 |
#✅✅ check if the command is in the allowed channel(s)
|
101 |
bot_test = 1100458786826747945
|
102 |
-
|
103 |
-
|
104 |
-
sketch_channel = 1114218145343877180
|
105 |
-
spidey_channel = 1114218191594471514
|
106 |
-
falcon_channel = 1116089829147557999
|
107 |
-
|
108 |
-
channel_ids = [bot_test, deepfloydif_channel, jojo_channel, spidey_channel, sketch_channel, falcon_channel]
|
109 |
if ctx.channel.id not in channel_ids:
|
110 |
print(f"{ctx.author}, commands are not permitted in {ctx.channel}")
|
111 |
thread = await ctx.message.create_thread(name=f'Channel Error')
|
@@ -137,8 +121,8 @@ async def safetychecks(ctx):
|
|
137 |
|
138 |
# ping lunarflu if any safety check ever fails
|
139 |
except Exception as e:
|
140 |
-
print(f"Error: safetychecks failed somewhere, command will not continue
|
141 |
-
await ctx.message.reply(f"❌ <@811235357663297546> SC failed somewhere ❌
|
142 |
await ctx.message.add_reaction(failure_emoji)
|
143 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
144 |
@bot.command()
|
@@ -155,41 +139,13 @@ async def deepfloydifdemo(ctx):
|
|
155 |
@bot.command()
|
156 |
async def jojodemo(ctx):
|
157 |
try:
|
158 |
-
thread = await ctx.message.create_thread(name=f'
|
159 |
await thread.send(f'{ctx.author.mention} Here is a demo for the !jojo command!')
|
160 |
await asyncio.sleep(0.5)
|
161 |
-
await thread.send(f'https://cdn.discordapp.com/attachments/932563860597121054/
|
162 |
-
await thread.edit(archived=True)
|
163 |
-
except Exception as e:
|
164 |
-
print(f"Error: {e}")
|
165 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
166 |
-
await thread.edit(archived=True)
|
167 |
-
#----------------------------------------------------------------------------------------------------------------------------------------------
|
168 |
-
@bot.command()
|
169 |
-
async def sketchdemo(ctx):
|
170 |
-
try:
|
171 |
-
thread = await ctx.message.create_thread(name=f'Sketch Demo {ctx.author} ')
|
172 |
-
await thread.send(f'{ctx.author.mention} Here is a demo for the !sketch command!')
|
173 |
-
await asyncio.sleep(0.5)
|
174 |
-
await thread.send(f'https://cdn.discordapp.com/attachments/932563860597121054/1114220716498370641/image.png')
|
175 |
-
await thread.edit(archived=True)
|
176 |
-
except Exception as e:
|
177 |
-
print(f"Error: {e}")
|
178 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
179 |
-
await thread.edit(archived=True)
|
180 |
-
#----------------------------------------------------------------------------------------------------------------------------------------------
|
181 |
-
@bot.command()
|
182 |
-
async def spideydemo(ctx):
|
183 |
-
try:
|
184 |
-
thread = await ctx.message.create_thread(name=f'Spidey Demo {ctx.author} ')
|
185 |
-
await thread.send(f'{ctx.author.mention} Here is a demo for the !spidey command!')
|
186 |
-
await asyncio.sleep(0.5)
|
187 |
-
await thread.send(f'https://cdn.discordapp.com/attachments/932563860597121054/1114220798085959690/image.png')
|
188 |
-
await thread.edit(archived=True)
|
189 |
except Exception as e:
|
190 |
print(f"Error: {e}")
|
191 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
192 |
-
await thread.edit(archived=True)
|
193 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
194 |
# jojo ✅
|
195 |
@bot.command()
|
@@ -203,98 +159,114 @@ async def jojo(ctx):
|
|
203 |
# safety checks?✅
|
204 |
# bot no crash ✅
|
205 |
try:
|
206 |
-
if await safetychecks(ctx): #✅
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>') # ❌
|
227 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
228 |
-
await thread.edit(archived=True)
|
229 |
except Exception as e: # no generation / img + no face
|
230 |
await fullqueue(e, thread)
|
231 |
print(f"Error: {e}")
|
232 |
await thread.send(f"{ctx.author.mention} Error: {e}")
|
233 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
234 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
235 |
-
await thread.edit(archived=True)
|
236 |
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
239 |
# Spider-Verse ✅
|
240 |
@bot.command()
|
241 |
async def spidey(ctx):
|
242 |
try:
|
243 |
if await safetychecks(ctx): #✅
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
259 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
260 |
-
await thread.edit(archived=True)
|
261 |
except Exception as e: # no generation / img + no face
|
262 |
await fullqueue(e, thread)
|
263 |
print(f"Error: {e}")
|
264 |
await thread.send(f"{ctx.author.mention} Error: {e}")
|
265 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
266 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
267 |
-
|
268 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
269 |
# sketch ✅
|
270 |
@bot.command()
|
271 |
async def sketch(ctx):
|
272 |
try:
|
273 |
if await safetychecks(ctx): #✅
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
289 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
290 |
-
await thread.edit(archived=True)
|
291 |
except Exception as e: # no generation / img + no face
|
292 |
await fullqueue(e, thread)
|
293 |
print(f"Error: {e}")
|
294 |
await thread.send(f"{ctx.author.mention} Error: {e}")
|
295 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
296 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
297 |
-
await thread.edit(archived=True)
|
298 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
299 |
async def fullqueue(e, thread):
|
300 |
error_message = str(e)
|
@@ -302,13 +274,9 @@ async def fullqueue(e, thread):
|
|
302 |
await thread.send("Queue is full! Please try again.")
|
303 |
elif "Error: Queue is full! Please try again." in error_message:
|
304 |
await thread.send("Queue is full! Please try again.")
|
305 |
-
# raised when the space we depend on needs to build after some inactivity (~10h)
|
306 |
elif "local variable 'stage_1_results' referenced before assignment" in error_message:
|
307 |
-
await thread.send("
|
308 |
-
|
309 |
-
#----------------------------------------------------------------------------------------------------------------------------------------------
|
310 |
-
|
311 |
-
|
312 |
# deepfloydif stage 1 generation ✅
|
313 |
def inference(prompt):
|
314 |
negative_prompt = ''
|
@@ -344,49 +312,45 @@ async def react1234(reaction_emojis, combined_image_dfif):
|
|
344 |
# Stage 1 ✅
|
345 |
@bot.command()
|
346 |
async def deepfloydif(ctx, *, prompt: str):
|
347 |
-
thread = None
|
348 |
try:
|
349 |
try:
|
350 |
if await safetychecks(ctx): #✅
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
# create thread -> send new message inside thread + combined_image -> add reactions -> dfif2
|
356 |
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
|
370 |
except Exception as e:
|
371 |
print(f"Error: {e}")
|
372 |
-
|
373 |
-
|
374 |
-
await thread.send(f"{ctx.author.mention} Error before stage 1 generation, {e}. If error code: 50035, upscale can still work.")
|
375 |
await fullqueue(e, thread)
|
376 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
377 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
378 |
-
|
379 |
#generation✅-------------------------------------------------------
|
380 |
try:
|
381 |
#stage_1_results, stage_1_param_path, stage_1_result_path = df.predict(
|
382 |
# prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name='/generate64')
|
383 |
|
384 |
# run blocking function in executor
|
385 |
-
await thread.send(f'✅running blocking function in executor')
|
386 |
loop = asyncio.get_running_loop()
|
387 |
result = await loop.run_in_executor(None, inference, prompt)
|
388 |
-
await thread.send(f'
|
389 |
-
await thread.send(f'✅run_in_executor ran successfully')
|
390 |
stage_1_results = result[0]
|
391 |
stage_1_result_path = result[2]
|
392 |
|
@@ -394,20 +358,16 @@ async def deepfloydif(ctx, *, prompt: str):
|
|
394 |
|
395 |
except Exception as e:
|
396 |
print(f"Error: {e}")
|
397 |
-
|
398 |
-
|
399 |
-
await thread.send(f"{ctx.author.mention} Error during stage 1 generation, {e}")
|
400 |
await fullqueue(e, thread)
|
401 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
402 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
403 |
-
await thread.edit(archived=True)
|
404 |
#posting images✅----------------------------------------------------------------
|
405 |
try:
|
406 |
-
await thread.send(f'✅combining images...')
|
407 |
png_files = [f for f in os.listdir(stage_1_results) if f.endswith('.png')]
|
408 |
|
409 |
-
|
410 |
-
''' combined images
|
411 |
if png_files:
|
412 |
first_png = png_files[0]
|
413 |
second_png = png_files[1]
|
@@ -438,16 +398,11 @@ async def deepfloydif(ctx, *, prompt: str):
|
|
438 |
combined_image_dfif = await thread.send(f'{ctx.author.mention}React with the image number you want to upscale!', file=discord.File(
|
439 |
f, f'{partialpath}{dfif_command_message_id}.png')) # named something like: tmpgtv4qjix1111269940599738479.png
|
440 |
|
441 |
-
await thread.send(f'✅reacting with 1234...')
|
442 |
emoji_list = ['↖️', '↗️', '↙️', '↘️']
|
443 |
-
await react1234(emoji_list, combined_image_dfif)
|
444 |
-
'''
|
445 |
-
|
446 |
|
447 |
''' individual images
|
448 |
-
|
449 |
-
|
450 |
-
'''
|
451 |
if png_files:
|
452 |
for i, png_file in enumerate(png_files):
|
453 |
png_file_path = os.path.join(stage_1_results, png_file)
|
@@ -456,30 +411,27 @@ async def deepfloydif(ctx, *, prompt: str):
|
|
456 |
img.save(image_path)
|
457 |
with open(image_path, 'rb') as f:
|
458 |
await thread.send(f'{ctx.author.mention}Image {i+1}', file=discord.File(f, f'{i+1}{partialpath}.png'))
|
459 |
-
await asyncio.sleep(1)
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
|
464 |
except Exception as e:
|
465 |
print(f"Error: {e}")
|
466 |
-
|
467 |
-
|
468 |
-
await thread.send(f"{ctx.author.mention} Encountered error while posting combined image in thread, {e}")
|
469 |
await fullqueue(e, thread)
|
470 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
471 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
472 |
-
|
473 |
#deepfloydif try/except
|
474 |
except Exception as e:
|
475 |
print(f"Error: {e}")
|
476 |
-
|
477 |
-
|
478 |
-
await thread.send(f"{ctx.author.mention} Overall error with deepfloydif, {e}")
|
479 |
await fullqueue(e, thread)
|
480 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
481 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
482 |
-
|
483 |
#----------------------------------------------------------------------------------------------------------------------------
|
484 |
# Stage 2 ✅
|
485 |
async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id): # add safetychecks
|
@@ -507,7 +459,6 @@ async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id
|
|
507 |
dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
|
508 |
await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
509 |
await dfif_command_message.add_reaction('<:agree:1098629085955113011>')
|
510 |
-
await thread.edit(archived=True)
|
511 |
|
512 |
except Exception as e:
|
513 |
print(f"Error: {e}")
|
@@ -515,9 +466,8 @@ async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id
|
|
515 |
dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
|
516 |
await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
517 |
await dfif_command_message.add_reaction('<:disagree:1098628957521313892>')
|
518 |
-
await thread.send(f"Error during stage 2 upscaling
|
519 |
-
await fullqueue(e, thread)
|
520 |
-
await thread.edit(archived=True)
|
521 |
#----------------------------------------------------------------------------------------------------------------------------
|
522 |
# react detector for stage 2 ✅
|
523 |
@bot.event
|
@@ -567,73 +517,11 @@ async def on_reaction_add(reaction, user): # ctx = await bot.get_context(reac
|
|
567 |
await dfif2(index, stage_1_result_path, thread, dfif_command_message_id)
|
568 |
|
569 |
except Exception as e:
|
570 |
-
print(f"Error: {e}
|
571 |
|
572 |
|
573 |
#----------------------------------------------------------------------------------------------------------------------------
|
574 |
-
chathistory = None
|
575 |
-
|
576 |
-
@bot.command()
|
577 |
-
async def falcon(ctx, *, prompt: str):
|
578 |
-
try:
|
579 |
-
if await safetychecks(ctx):
|
580 |
-
if ctx.channel.id == 1116089829147557999:
|
581 |
-
global chathistory
|
582 |
-
|
583 |
-
if chathistory is not None: # This handles all subsequent discussions/prompts to the chatbot/model
|
584 |
-
instructions = "The following is a conversation between a highly knowledgeable and intelligent AI assistant, called Falcon, and a human user, called User. In the following interactions, User and Falcon will converse in natural language, and Falcon will answer User's questions. Falcon was built to be respectful, polite and inclusive. Falcon was built by the Technology Innovation Institute in Abu Dhabi. Falcon will never decline to answer a question, and always attempts to give an answer that User would be satisfied with. It knows a lot, and always tells the truth. The conversation begins."
|
585 |
-
job = falconclient.submit(prompt, chathistory, instructions, 0.8, 0.9, fn_index=1) # This is not blocking
|
586 |
-
while job.done() == False:
|
587 |
-
status = job.status()
|
588 |
-
else:
|
589 |
-
file_paths = job.outputs()
|
590 |
-
full_generation = file_paths[-1]
|
591 |
-
chathistory = full_generation # we store this and pass it in the loop
|
592 |
-
with open(full_generation, 'r') as file:
|
593 |
-
data = json.load(file)
|
594 |
-
output_text = data[-1][-1] # we output this as the bot
|
595 |
-
print(output_text)
|
596 |
-
await ctx.reply(f"{output_text}")
|
597 |
-
|
598 |
-
if chathistory == None: # This handles the start of a conversation/chathistory file with the model
|
599 |
-
chathistory = falconclient.predict(
|
600 |
-
fn_index=5
|
601 |
-
)
|
602 |
-
instructions = "The following is a conversation between a highly knowledgeable and intelligent AI assistant, called Falcon, and a human user, called User. In the following interactions, User and Falcon will converse in natural language, and Falcon will answer User's questions. Falcon was built to be respectful, polite and inclusive. Falcon was built by the Technology Innovation Institute in Abu Dhabi. Falcon will never decline to answer a question, and always attempts to give an answer that User would be satisfied with. It knows a lot, and always tells the truth. The conversation begins."
|
603 |
-
job = falconclient.submit(prompt, chathistory, instructions, 0.8, 0.9, fn_index=1) # This is not blocking
|
604 |
-
while job.done() == False:
|
605 |
-
status = job.status()
|
606 |
-
else:
|
607 |
-
file_paths = job.outputs()
|
608 |
-
full_generation = file_paths[-1]
|
609 |
-
chathistory = full_generation # we store this and pass it in the loop
|
610 |
-
with open(full_generation, 'r') as file:
|
611 |
-
data = json.load(file)
|
612 |
-
output_text = data[-1][-1] # we output this as the bot
|
613 |
-
await ctx.reply(f"{output_text}")
|
614 |
-
|
615 |
-
except Exception as e:
|
616 |
-
print(f"Error: {e}")
|
617 |
-
await ctx.reply(f"{e} cc <@811235357663297546> (falcon error)")
|
618 |
-
#----------------------------------------------------------------------------------------------------------------------------
|
619 |
-
'''
|
620 |
-
@bot.event
|
621 |
-
async def on_message(message):
|
622 |
-
try:
|
623 |
-
if message.channel.id == 1116089829147557999:
|
624 |
|
625 |
-
|
626 |
-
|
627 |
-
except Exception as e:
|
628 |
-
print(f"Error: {e}")
|
629 |
-
await ctx.reply(f"{e} cc <@811235357663297546> (falcon error)")
|
630 |
-
|
631 |
-
'''
|
632 |
-
#----------------------------------------------------------------------------------------------------------------------------
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
def run_bot():
|
638 |
bot.run(DISCORD_TOKEN)
|
639 |
|
|
|
9 |
import re
|
10 |
from discord import Embed, Color
|
11 |
from discord.ext import commands
|
12 |
+
# test # fix? # unstick # fix
|
13 |
from gradio_client import Client
|
14 |
from PIL import Image
|
15 |
#from ratelimiter import RateLimiter
|
|
|
20 |
|
21 |
import shutil # for doing image movement magic
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
#todo
|
24 |
# add safetychecks to all parts, test thoroughly
|
25 |
# add discord channels, configure for fellows
|
|
|
46 |
|
47 |
df = Client("huggingface-projects/IF", GRADIOTEST_TOKEN)
|
48 |
jojogan = Client("akhaliq/JoJoGAN", GRADIOTEST_TOKEN)
|
49 |
+
|
50 |
|
51 |
intents = discord.Intents.default()
|
52 |
intents.message_content = True
|
53 |
|
54 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
55 |
|
56 |
+
|
|
|
|
|
|
|
|
|
|
|
57 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
58 |
@bot.event
|
59 |
async def on_ready():
|
|
|
66 |
if await safetychecks(ctx):
|
67 |
await ctx.reply(f"Use !deepfloydif [prompt], !jojo !spidey or !sketch. Have fun! 🤗💖")
|
68 |
except Exception as e:
|
69 |
+
print(f"Error: unable to help :(")
|
70 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
71 |
async def safetychecks(ctx):
|
72 |
failure_emoji = '<:disagree:1098628957521313892>'
|
|
|
88 |
|
89 |
#✅✅ check if the command is in the allowed channel(s)
|
90 |
bot_test = 1100458786826747945
|
91 |
+
testing_the_bot = 1113182673859518514
|
92 |
+
channel_ids = [bot_test, testing_the_bot]
|
|
|
|
|
|
|
|
|
|
|
93 |
if ctx.channel.id not in channel_ids:
|
94 |
print(f"{ctx.author}, commands are not permitted in {ctx.channel}")
|
95 |
thread = await ctx.message.create_thread(name=f'Channel Error')
|
|
|
121 |
|
122 |
# ping lunarflu if any safety check ever fails
|
123 |
except Exception as e:
|
124 |
+
print(f"Error: safetychecks failed somewhere, command will not continue.")
|
125 |
+
await ctx.message.reply(f"❌ <@811235357663297546> SC failed somewhere ❌") # this will always ping, as long as the bot has access to the channel
|
126 |
await ctx.message.add_reaction(failure_emoji)
|
127 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
128 |
@bot.command()
|
|
|
139 |
@bot.command()
|
140 |
async def jojodemo(ctx):
|
141 |
try:
|
142 |
+
thread = await ctx.message.create_thread(name=f'{ctx.author} Demo Thread')
|
143 |
await thread.send(f'{ctx.author.mention} Here is a demo for the !jojo command!')
|
144 |
await asyncio.sleep(0.5)
|
145 |
+
await thread.send(f'https://cdn.discordapp.com/attachments/932563860597121054/1113492260294770778/image.png')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
except Exception as e:
|
147 |
print(f"Error: {e}")
|
148 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
|
|
149 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
150 |
# jojo ✅
|
151 |
@bot.command()
|
|
|
159 |
# safety checks?✅
|
160 |
# bot no crash ✅
|
161 |
try:
|
162 |
+
if await safetychecks(ctx): #✅
|
163 |
+
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
164 |
+
thread = await ctx.message.create_thread(name=f'{ctx.author} Jojo Thread')
|
165 |
+
if ctx.message.attachments:
|
166 |
+
await thread.send(f'{ctx.author.mention} Generating images in thread, can take ~1 minute...yare yare, daze ...')
|
167 |
+
attachment = ctx.message.attachments[0]
|
168 |
+
style = 'JoJo'
|
169 |
+
#im = jojogan.predict(attachment.url, style)
|
170 |
+
im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
|
171 |
+
#await ctx.message.reply(f'Here is the {style} version of it', file=discord.File(im))
|
172 |
+
await thread.send(f'{ctx.author.mention} Here is the {style} version of it', file=discord.File(im))
|
173 |
+
|
174 |
+
#testing animated
|
175 |
+
# <a:hugging_spin:1102656012621713488>
|
176 |
+
await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
|
177 |
+
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
178 |
+
else: # no image
|
179 |
+
await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
|
180 |
+
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
181 |
+
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
|
|
|
|
|
|
182 |
except Exception as e: # no generation / img + no face
|
183 |
await fullqueue(e, thread)
|
184 |
print(f"Error: {e}")
|
185 |
await thread.send(f"{ctx.author.mention} Error: {e}")
|
186 |
+
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
187 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
|
|
188 |
|
189 |
+
#----------------------------------------------------------------------------------------------------------------------------------------------
|
190 |
+
# Disney ❌
|
191 |
+
@bot.command()
|
192 |
+
async def disney(ctx):
|
193 |
+
try:
|
194 |
+
if await safetychecks(ctx): #✅
|
195 |
+
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
196 |
+
thread = await ctx.message.create_thread(name=f'{ctx.author} disney Thread')
|
197 |
+
if ctx.message.attachments:
|
198 |
+
await thread.send(f'{ctx.author.mention} Generating images in thread, can take ~1 minute...')
|
199 |
+
attachment = ctx.message.attachments[0]
|
200 |
+
style = 'Disney'
|
201 |
+
im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, 'disney')
|
202 |
+
await thread.send(f'{ctx.author.mention} Here is the {style} version of it', file=discord.File(im))
|
203 |
+
await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
|
204 |
+
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
205 |
+
else: # no image
|
206 |
+
await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
|
207 |
+
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
208 |
+
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
209 |
+
|
210 |
+
except Exception as e: # no generation / img + no face
|
211 |
+
await fullqueue(e, thread)
|
212 |
+
print(f"Error: {e}")
|
213 |
+
await thread.send(f"{ctx.author.mention} Error: {e}")
|
214 |
+
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
215 |
+
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
216 |
+
|
217 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
218 |
# Spider-Verse ✅
|
219 |
@bot.command()
|
220 |
async def spidey(ctx):
|
221 |
try:
|
222 |
if await safetychecks(ctx): #✅
|
223 |
+
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
224 |
+
thread = await ctx.message.create_thread(name=f'{ctx.author} spider-verse Thread')
|
225 |
+
if ctx.message.attachments:
|
226 |
+
await thread.send(f'{ctx.author.mention} Generating images in thread, can take ~1 minute...')
|
227 |
+
attachment = ctx.message.attachments[0]
|
228 |
+
style = 'Spider-Verse'
|
229 |
+
im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
|
230 |
+
await thread.send(f'{ctx.author.mention} Here is the {style} version of it', file=discord.File(im))
|
231 |
+
await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
|
232 |
+
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
233 |
+
else: # no image
|
234 |
+
await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
|
235 |
+
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
236 |
+
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
|
|
|
|
|
|
237 |
except Exception as e: # no generation / img + no face
|
238 |
await fullqueue(e, thread)
|
239 |
print(f"Error: {e}")
|
240 |
await thread.send(f"{ctx.author.mention} Error: {e}")
|
241 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
242 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
243 |
+
|
244 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
245 |
# sketch ✅
|
246 |
@bot.command()
|
247 |
async def sketch(ctx):
|
248 |
try:
|
249 |
if await safetychecks(ctx): #✅
|
250 |
+
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
251 |
+
thread = await ctx.message.create_thread(name=f'{ctx.author} sketch Thread')
|
252 |
+
if ctx.message.attachments:
|
253 |
+
await thread.send(f'{ctx.author.mention} Generating images in thread, can take ~1 minute...')
|
254 |
+
attachment = ctx.message.attachments[0]
|
255 |
+
#style = 'sketch'
|
256 |
+
im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, 'sketch')
|
257 |
+
await thread.send(f'{ctx.author.mention} Here is the sketch version of it', file=discord.File(im))
|
258 |
+
await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
|
259 |
+
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
260 |
+
else: # no image
|
261 |
+
await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
|
262 |
+
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
263 |
+
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
|
|
|
|
|
|
264 |
except Exception as e: # no generation / img + no face
|
265 |
await fullqueue(e, thread)
|
266 |
print(f"Error: {e}")
|
267 |
await thread.send(f"{ctx.author.mention} Error: {e}")
|
268 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
269 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
|
|
270 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
271 |
async def fullqueue(e, thread):
|
272 |
error_message = str(e)
|
|
|
274 |
await thread.send("Queue is full! Please try again.")
|
275 |
elif "Error: Queue is full! Please try again." in error_message:
|
276 |
await thread.send("Queue is full! Please try again.")
|
|
|
277 |
elif "local variable 'stage_1_results' referenced before assignment" in error_message:
|
278 |
+
await thread.send("Queue is full! Please try again.")
|
279 |
+
#----------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
280 |
# deepfloydif stage 1 generation ✅
|
281 |
def inference(prompt):
|
282 |
negative_prompt = ''
|
|
|
312 |
# Stage 1 ✅
|
313 |
@bot.command()
|
314 |
async def deepfloydif(ctx, *, prompt: str):
|
|
|
315 |
try:
|
316 |
try:
|
317 |
if await safetychecks(ctx): #✅
|
318 |
+
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
319 |
+
dfif_command_message_id = ctx.message.id # we will use this in some magic later on
|
320 |
+
thread = await ctx.message.create_thread(name=f'{ctx.author} DeepfloydIF Image Upscaling Thread ')
|
321 |
+
# create thread -> send new message inside thread + combined_image -> add reactions -> dfif2
|
|
|
322 |
|
323 |
+
#current_time = int(time.time())
|
324 |
+
#random.seed(current_time)
|
325 |
+
|
326 |
+
negative_prompt = ''
|
327 |
+
seed = random.randint(0, 1000)
|
328 |
+
#seed = 1
|
329 |
+
number_of_images = 4
|
330 |
+
guidance_scale = 7
|
331 |
+
custom_timesteps_1 = 'smart50'
|
332 |
+
number_of_inference_steps = 50
|
333 |
+
api_name = '/generate64'
|
334 |
+
await thread.send(f'{ctx.author.mention}Generating images in thread, can take ~1 minute...')
|
335 |
|
336 |
except Exception as e:
|
337 |
print(f"Error: {e}")
|
338 |
+
thread = await ctx.message.create_thread(name=f'DFIF1 Error')
|
339 |
+
await thread.send(f"{ctx.author.mention} Error during stage 1 pre-generation.")
|
|
|
340 |
await fullqueue(e, thread)
|
341 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
342 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
343 |
+
|
344 |
#generation✅-------------------------------------------------------
|
345 |
try:
|
346 |
#stage_1_results, stage_1_param_path, stage_1_result_path = df.predict(
|
347 |
# prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name='/generate64')
|
348 |
|
349 |
# run blocking function in executor
|
350 |
+
#await thread.send(f'✅running blocking function in executor')
|
351 |
loop = asyncio.get_running_loop()
|
352 |
result = await loop.run_in_executor(None, inference, prompt)
|
353 |
+
#await thread.send(f'✅run_in_executor ran successfully')
|
|
|
354 |
stage_1_results = result[0]
|
355 |
stage_1_result_path = result[2]
|
356 |
|
|
|
358 |
|
359 |
except Exception as e:
|
360 |
print(f"Error: {e}")
|
361 |
+
thread = await ctx.message.create_thread(name=f'Generation Error')
|
362 |
+
await thread.send(f"{ctx.author.mention} Error during stage 1 generation.")
|
|
|
363 |
await fullqueue(e, thread)
|
364 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
365 |
+
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
|
|
366 |
#posting images✅----------------------------------------------------------------
|
367 |
try:
|
368 |
+
#await thread.send(f'✅combining images...')
|
369 |
png_files = [f for f in os.listdir(stage_1_results) if f.endswith('.png')]
|
370 |
|
|
|
|
|
371 |
if png_files:
|
372 |
first_png = png_files[0]
|
373 |
second_png = png_files[1]
|
|
|
398 |
combined_image_dfif = await thread.send(f'{ctx.author.mention}React with the image number you want to upscale!', file=discord.File(
|
399 |
f, f'{partialpath}{dfif_command_message_id}.png')) # named something like: tmpgtv4qjix1111269940599738479.png
|
400 |
|
401 |
+
#await thread.send(f'✅reacting with 1234...')
|
402 |
emoji_list = ['↖️', '↗️', '↙️', '↘️']
|
403 |
+
await react1234(emoji_list, combined_image_dfif)
|
|
|
|
|
404 |
|
405 |
''' individual images
|
|
|
|
|
|
|
406 |
if png_files:
|
407 |
for i, png_file in enumerate(png_files):
|
408 |
png_file_path = os.path.join(stage_1_results, png_file)
|
|
|
411 |
img.save(image_path)
|
412 |
with open(image_path, 'rb') as f:
|
413 |
await thread.send(f'{ctx.author.mention}Image {i+1}', file=discord.File(f, f'{i+1}{partialpath}.png'))
|
414 |
+
await asyncio.sleep(1)
|
415 |
+
|
416 |
+
'''
|
|
|
417 |
|
418 |
except Exception as e:
|
419 |
print(f"Error: {e}")
|
420 |
+
thread = await ctx.message.create_thread(name=f'Posting Error')
|
421 |
+
await thread.send(f"{ctx.author.mention} Encountered error while posting combined image in thread.")
|
|
|
422 |
await fullqueue(e, thread)
|
423 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
424 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
425 |
+
|
426 |
#deepfloydif try/except
|
427 |
except Exception as e:
|
428 |
print(f"Error: {e}")
|
429 |
+
thread = await ctx.message.create_thread(name=f'deepfloydif Error')
|
430 |
+
await thread.send(f"{ctx.author.mention} Overall error with deepfloydif.")
|
|
|
431 |
await fullqueue(e, thread)
|
432 |
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
433 |
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
434 |
+
|
435 |
#----------------------------------------------------------------------------------------------------------------------------
|
436 |
# Stage 2 ✅
|
437 |
async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id): # add safetychecks
|
|
|
459 |
dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
|
460 |
await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
461 |
await dfif_command_message.add_reaction('<:agree:1098629085955113011>')
|
|
|
462 |
|
463 |
except Exception as e:
|
464 |
print(f"Error: {e}")
|
|
|
466 |
dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
|
467 |
await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
468 |
await dfif_command_message.add_reaction('<:disagree:1098628957521313892>')
|
469 |
+
await thread.send(f"Error during stage 2 upscaling.")
|
470 |
+
await fullqueue(e, thread)
|
|
|
471 |
#----------------------------------------------------------------------------------------------------------------------------
|
472 |
# react detector for stage 2 ✅
|
473 |
@bot.event
|
|
|
517 |
await dfif2(index, stage_1_result_path, thread, dfif_command_message_id)
|
518 |
|
519 |
except Exception as e:
|
520 |
+
print(f"Error: {e} testing emoji behavior with reacts")
|
521 |
|
522 |
|
523 |
#----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
def run_bot():
|
526 |
bot.run(DISCORD_TOKEN)
|
527 |
|