lunarflu HF Staff commited on
Commit
bf3bffa
·
1 Parent(s): cdfdf62

fixing some redundant thread creation, adding both auto_archive_duration=60 as well as manual instant archiving upon error / stage 2 completion [dfif]

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -205,10 +205,12 @@ async def disney(ctx):
205
  await thread.send(f'{ctx.author.mention} Here is the {style} version of it', file=discord.File(im))
206
  await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
207
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
 
208
  else: # no image
209
  await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
210
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
211
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
 
212
 
213
  except Exception as e: # no generation / img + no face
214
  await fullqueue(e, thread)
@@ -216,7 +218,7 @@ async def disney(ctx):
216
  await thread.send(f"{ctx.author.mention} Error: {e}")
217
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
218
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
219
-
220
  #----------------------------------------------------------------------------------------------------------------------------------------------
221
  # Spider-Verse ✅
222
  @bot.command()
@@ -232,18 +234,20 @@ async def spidey(ctx):
232
  im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
233
  await thread.send(f'{ctx.author.mention} Here is the {style} version of it', file=discord.File(im))
234
  await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
235
- await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
 
236
  else: # no image
237
  await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
238
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
239
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
 
240
  except Exception as e: # no generation / img + no face
241
  await fullqueue(e, thread)
242
  print(f"Error: {e}")
243
  await thread.send(f"{ctx.author.mention} Error: {e}")
244
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
245
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
246
-
247
  #----------------------------------------------------------------------------------------------------------------------------------------------
248
  # sketch ✅
249
  @bot.command()
@@ -259,17 +263,20 @@ async def sketch(ctx):
259
  im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, 'sketch')
260
  await thread.send(f'{ctx.author.mention} Here is the sketch version of it', file=discord.File(im))
261
  await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
262
- await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
 
263
  else: # no image
264
  await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
265
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
266
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
 
267
  except Exception as e: # no generation / img + no face
268
  await fullqueue(e, thread)
269
  print(f"Error: {e}")
270
  await thread.send(f"{ctx.author.mention} Error: {e}")
271
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
272
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
 
273
  #----------------------------------------------------------------------------------------------------------------------------------------------
274
  async def fullqueue(e, thread):
275
  error_message = str(e)
@@ -338,12 +345,13 @@ async def deepfloydif(ctx, *, prompt: str):
338
 
339
  except Exception as e:
340
  print(f"Error: {e}")
341
- thread = await ctx.message.create_thread(name=f'DFIF1 Error')
 
342
  await thread.send(f"{ctx.author.mention} Error during stage 1 pre-generation.")
343
  await fullqueue(e, thread)
344
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
345
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
346
-
347
  #generation✅-------------------------------------------------------
348
  try:
349
  #stage_1_results, stage_1_param_path, stage_1_result_path = df.predict(
@@ -361,11 +369,13 @@ async def deepfloydif(ctx, *, prompt: str):
361
 
362
  except Exception as e:
363
  print(f"Error: {e}")
364
- thread = await ctx.message.create_thread(name=f'Generation Error')
 
365
  await thread.send(f"{ctx.author.mention} Error during stage 1 generation.")
366
  await fullqueue(e, thread)
367
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
368
- await ctx.message.add_reaction('<:disagree:1098628957521313892>')
 
369
  #posting images✅----------------------------------------------------------------
370
  try:
371
  #await thread.send(f'✅combining images...')
@@ -426,7 +436,7 @@ async def deepfloydif(ctx, *, prompt: str):
426
  await fullqueue(e, thread)
427
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
428
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
429
-
430
  #deepfloydif try/except
431
  except Exception as e:
432
  print(f"Error: {e}")
@@ -436,7 +446,7 @@ async def deepfloydif(ctx, *, prompt: str):
436
  await fullqueue(e, thread)
437
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
438
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
439
-
440
  #----------------------------------------------------------------------------------------------------------------------------
441
  # Stage 2 ✅
442
  async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id): # add safetychecks
@@ -464,6 +474,7 @@ async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id
464
  dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
465
  await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
466
  await dfif_command_message.add_reaction('<:agree:1098629085955113011>')
 
467
 
468
  except Exception as e:
469
  print(f"Error: {e}")
@@ -472,7 +483,8 @@ async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id
472
  await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
473
  await dfif_command_message.add_reaction('<:disagree:1098628957521313892>')
474
  await thread.send(f"Error during stage 2 upscaling.")
475
- await fullqueue(e, thread)
 
476
  #----------------------------------------------------------------------------------------------------------------------------
477
  # react detector for stage 2 ✅
478
  @bot.event
@@ -522,7 +534,7 @@ async def on_reaction_add(reaction, user): # ctx = await bot.get_context(reac
522
  await dfif2(index, stage_1_result_path, thread, dfif_command_message_id)
523
 
524
  except Exception as e:
525
- print(f"Error: {e} testing emoji behavior with reacts")
526
 
527
 
528
  #----------------------------------------------------------------------------------------------------------------------------
 
205
  await thread.send(f'{ctx.author.mention} Here is the {style} version of it', file=discord.File(im))
206
  await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
207
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
208
+ await thread.edit(archived=True)
209
  else: # no image
210
  await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
211
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
212
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
213
+ await thread.edit(archived=True)
214
 
215
  except Exception as e: # no generation / img + no face
216
  await fullqueue(e, thread)
 
218
  await thread.send(f"{ctx.author.mention} Error: {e}")
219
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
220
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
221
+ await thread.edit(archived=True)
222
  #----------------------------------------------------------------------------------------------------------------------------------------------
223
  # Spider-Verse ✅
224
  @bot.command()
 
234
  im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
235
  await thread.send(f'{ctx.author.mention} Here is the {style} version of it', file=discord.File(im))
236
  await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
237
+ await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
238
+ await thread.edit(archived=True)
239
  else: # no image
240
  await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
241
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
242
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
243
+ await thread.edit(archived=True)
244
  except Exception as e: # no generation / img + no face
245
  await fullqueue(e, thread)
246
  print(f"Error: {e}")
247
  await thread.send(f"{ctx.author.mention} Error: {e}")
248
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
249
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
250
+ await thread.edit(archived=True)
251
  #----------------------------------------------------------------------------------------------------------------------------------------------
252
  # sketch ✅
253
  @bot.command()
 
263
  im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, 'sketch')
264
  await thread.send(f'{ctx.author.mention} Here is the sketch version of it', file=discord.File(im))
265
  await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
266
+ await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
267
+ await thread.edit(archived=True)
268
  else: # no image
269
  await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image 😉")
270
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
271
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
272
+ await thread.edit(archived=True)
273
  except Exception as e: # no generation / img + no face
274
  await fullqueue(e, thread)
275
  print(f"Error: {e}")
276
  await thread.send(f"{ctx.author.mention} Error: {e}")
277
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
278
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
279
+ await thread.edit(archived=True)
280
  #----------------------------------------------------------------------------------------------------------------------------------------------
281
  async def fullqueue(e, thread):
282
  error_message = str(e)
 
345
 
346
  except Exception as e:
347
  print(f"Error: {e}")
348
+ if thread is Null:
349
+ thread = await ctx.message.create_thread(name=f'DFIF1 Error')
350
  await thread.send(f"{ctx.author.mention} Error during stage 1 pre-generation.")
351
  await fullqueue(e, thread)
352
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
353
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
354
+ await thread.edit(archived=True)
355
  #generation✅-------------------------------------------------------
356
  try:
357
  #stage_1_results, stage_1_param_path, stage_1_result_path = df.predict(
 
369
 
370
  except Exception as e:
371
  print(f"Error: {e}")
372
+ if thread is Null:
373
+ thread = await ctx.message.create_thread(name=f'Generation Error')
374
  await thread.send(f"{ctx.author.mention} Error during stage 1 generation.")
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
+ await thread.edit(archived=True)
379
  #posting images✅----------------------------------------------------------------
380
  try:
381
  #await thread.send(f'✅combining images...')
 
436
  await fullqueue(e, thread)
437
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
438
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
439
+ await thread.edit(archived=True)
440
  #deepfloydif try/except
441
  except Exception as e:
442
  print(f"Error: {e}")
 
446
  await fullqueue(e, thread)
447
  await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
448
  await ctx.message.add_reaction('<:disagree:1098628957521313892>')
449
+ await thread.edit(archived=True)
450
  #----------------------------------------------------------------------------------------------------------------------------
451
  # Stage 2 ✅
452
  async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id): # add safetychecks
 
474
  dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
475
  await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
476
  await dfif_command_message.add_reaction('<:agree:1098629085955113011>')
477
+ await thread.edit(archived=True)
478
 
479
  except Exception as e:
480
  print(f"Error: {e}")
 
483
  await dfif_command_message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
484
  await dfif_command_message.add_reaction('<:disagree:1098628957521313892>')
485
  await thread.send(f"Error during stage 2 upscaling.")
486
+ await fullqueue(e, thread)
487
+ await thread.edit(archived=True)
488
  #----------------------------------------------------------------------------------------------------------------------------
489
  # react detector for stage 2 ✅
490
  @bot.event
 
534
  await dfif2(index, stage_1_result_path, thread, dfif_command_message_id)
535
 
536
  except Exception as e:
537
+ print(f"Error: {e} (known error, does not cause issues, fix later)")
538
 
539
 
540
  #----------------------------------------------------------------------------------------------------------------------------