reorganization
Browse files
app.py
CHANGED
@@ -35,70 +35,79 @@ bot = commands.Bot(command_prefix='!', intents=intents)
|
|
35 |
@bot.command()
|
36 |
async def active(ctx):
|
37 |
# get the number of active threads
|
38 |
-
activethreadcount = active_count()
|
39 |
await ctx.message.reply(f'active threads: {activethreadcount}')
|
40 |
|
41 |
@bot.command()
|
42 |
async def jojo(ctx):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# get the number of active threads
|
45 |
activethreadcount = active_count()
|
46 |
# report the number of active threads
|
47 |
print(activethreadcount)
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
if ctx.message.attachments:
|
56 |
-
await asyncio.gather(
|
57 |
-
ctx.message.add_reaction('π€'),
|
58 |
-
asyncio.sleep(0.5),
|
59 |
-
ctx.message.add_reaction('β')
|
60 |
-
)
|
61 |
-
attachment = ctx.message.attachments[0]
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
else:
|
70 |
await asyncio.gather(
|
71 |
ctx.send(f"{ctx.author.mention} No attachments to be found... Can't animify dat! Try sending me an image π"),
|
72 |
asyncio.sleep(0.5),
|
73 |
ctx.message.add_reaction('β')
|
74 |
)
|
75 |
-
return None
|
76 |
-
|
77 |
-
async def generation(ctx, attachment):
|
78 |
-
if attachment:
|
79 |
-
style = 'JoJo'
|
80 |
-
im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
|
81 |
-
#im = await asyncio.to_thread(jojogan.predict, attachment.url, style)
|
82 |
-
#im = jojogan.predict(attachment.url, style)
|
83 |
-
|
84 |
-
# get the number of active threads
|
85 |
-
activethreadcount = active_count()
|
86 |
-
# report the number of active threads
|
87 |
-
print(activethreadcount)
|
88 |
-
|
89 |
-
await asyncio.gather(
|
90 |
-
ctx.send(f'{ctx.author.mention} Here is the jojo version of it'),
|
91 |
-
asyncio.sleep(0.5),
|
92 |
-
ctx.send(file=discord.File(im)),
|
93 |
-
asyncio.sleep(0.5),
|
94 |
-
ctx.message.remove_reaction('β', bot.user),
|
95 |
-
asyncio.sleep(0.5),
|
96 |
-
ctx.message.add_reaction('β
')
|
97 |
-
)
|
98 |
|
99 |
|
100 |
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
|
104 |
#--------------------------------------------------------
|
@@ -128,13 +137,7 @@ demo.launch()
|
|
128 |
|
129 |
|
130 |
'''
|
131 |
-
|
132 |
-
await asyncio.gather(
|
133 |
-
ctx.send(f'{ctx.author.mention} Here is the jojo version of it'),
|
134 |
-
ctx.send(file=discord.File(im)),
|
135 |
-
ctx.message.remove_reaction('β', bot.user),
|
136 |
-
ctx.message.add_reaction('β
')
|
137 |
-
)
|
138 |
|
139 |
'''
|
140 |
|
|
|
35 |
@bot.command()
|
36 |
async def active(ctx):
|
37 |
# get the number of active threads
|
38 |
+
activethreadcount = threading.active_count() # was active_count()
|
39 |
await ctx.message.reply(f'active threads: {activethreadcount}')
|
40 |
|
41 |
@bot.command()
|
42 |
async def jojo(ctx):
|
43 |
+
#new
|
44 |
+
await asyncio.get_running_loop().run_in_executor(None, run_jojo, ctx) #do magically
|
45 |
+
|
46 |
+
async def run_jojo(ctx):
|
47 |
+
safety = await safety_checks(ctx)
|
48 |
+
if safety:
|
49 |
+
#discord before
|
50 |
+
attachment = await discord_before(ctx)
|
51 |
+
#generation
|
52 |
+
generated_image = await generation(attachment)
|
53 |
+
#discord after
|
54 |
+
await discord_after(ctx, generated_image)
|
55 |
+
|
56 |
+
async def discord_before(ctx):
|
57 |
+
await asyncio.gather(
|
58 |
+
ctx.message.add_reaction('π€'),
|
59 |
+
asyncio.sleep(0.5),
|
60 |
+
ctx.message.add_reaction('β')
|
61 |
+
)
|
62 |
+
attachment = ctx.message.attachments[0]
|
63 |
|
64 |
# get the number of active threads
|
65 |
activethreadcount = active_count()
|
66 |
# report the number of active threads
|
67 |
print(activethreadcount)
|
68 |
+
return attachment
|
69 |
+
|
70 |
+
async def generation(attachment):
|
71 |
+
style = 'JoJo'
|
72 |
+
#im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
|
73 |
+
#im = await asyncio.to_thread(jojogan.predict, attachment.url, style)
|
74 |
+
generated_image = jojogan.predict(attachment.url, style)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
# get the number of active threads
|
77 |
+
activethreadcount = active_count()
|
78 |
+
# report the number of active threads
|
79 |
+
print(activethreadcount)
|
80 |
+
return generated_image
|
81 |
|
82 |
+
async def discord_after(ctx, generated_image):
|
83 |
+
await asyncio.gather(
|
84 |
+
ctx.send(f'{ctx.author.mention} Here is the jojo version of it', file=discord.File(generated_image)),
|
85 |
+
asyncio.sleep(0.5),
|
86 |
+
ctx.message.remove_reaction('β', bot.user),
|
87 |
+
asyncio.sleep(0.5),
|
88 |
+
ctx.message.add_reaction('β
')
|
89 |
+
)
|
90 |
+
|
91 |
+
async def safety_checks(ctx):
|
92 |
+
if ctx.message.attachments:
|
93 |
+
return True
|
94 |
else:
|
95 |
await asyncio.gather(
|
96 |
ctx.send(f"{ctx.author.mention} No attachments to be found... Can't animify dat! Try sending me an image π"),
|
97 |
asyncio.sleep(0.5),
|
98 |
ctx.message.add_reaction('β')
|
99 |
)
|
100 |
+
return None
|
101 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
|
104 |
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
|
112 |
|
113 |
#--------------------------------------------------------
|
|
|
137 |
|
138 |
|
139 |
'''
|
140 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
'''
|
143 |
|