revert to [stable] parallelism with times
Browse files
app.py
CHANGED
@@ -35,72 +35,72 @@ bot = commands.Bot(command_prefix='!', intents=intents)
|
|
35 |
@bot.command()
|
36 |
async def active(ctx):
|
37 |
# get the number of active threads
|
38 |
-
activethreadcount =
|
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 |
-
def run_jojo(ctx):
|
47 |
-
safety = await safety_checks(ctx)
|
48 |
-
if safety:
|
49 |
-
start_time = time.time()
|
50 |
-
#discord before
|
51 |
-
attachment = await discord_before(ctx)
|
52 |
-
#generation
|
53 |
-
generated_image = await generation(attachment)
|
54 |
-
#discord after
|
55 |
-
end_time = time.time()
|
56 |
-
total_time = end_time - start_time
|
57 |
-
await discord_after(ctx, generated_image, total_time)
|
58 |
-
|
59 |
-
async def discord_before(ctx):
|
60 |
-
await asyncio.gather(
|
61 |
-
ctx.message.add_reaction('π€'),
|
62 |
-
asyncio.sleep(0.5),
|
63 |
-
ctx.message.add_reaction('β')
|
64 |
-
)
|
65 |
-
attachment = ctx.message.attachments[0]
|
66 |
-
|
67 |
-
# get the number of active threads
|
68 |
-
activethreadcount = active_count()
|
69 |
-
# report the number of active threads
|
70 |
-
print(activethreadcount)
|
71 |
-
return attachment
|
72 |
-
|
73 |
-
async def generation(attachment):
|
74 |
-
style = 'JoJo'
|
75 |
-
#im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
|
76 |
-
#im = await asyncio.to_thread(jojogan.predict, attachment.url, style)
|
77 |
-
generated_image = jojogan.predict(attachment.url, style)
|
78 |
|
79 |
# get the number of active threads
|
80 |
activethreadcount = active_count()
|
81 |
# report the number of active threads
|
82 |
print(activethreadcount)
|
83 |
-
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
async def
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
97 |
else:
|
98 |
await asyncio.gather(
|
99 |
ctx.send(f"{ctx.author.mention} No attachments to be found... Can't animify dat! Try sending me an image π"),
|
100 |
asyncio.sleep(0.5),
|
101 |
ctx.message.add_reaction('β')
|
102 |
)
|
103 |
-
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
#--------------------------------------------------------
|
106 |
def get_total_threads():
|
@@ -127,3 +127,31 @@ demo.launch()
|
|
127 |
#--------------------------------------------------------
|
128 |
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
start_time = time.time()
|
49 |
+
attachment = await discord_before(ctx)
|
50 |
+
if attachment:
|
51 |
+
asyncio.create_task(generation(ctx, attachment))
|
52 |
+
#await generation(ctx, attachment)
|
53 |
|
54 |
+
async def discord_before(ctx):
|
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 |
+
# get the number of active threads
|
64 |
+
activethreadcount = active_count()
|
65 |
+
# report the number of active threads
|
66 |
+
print(activethreadcount)
|
67 |
+
|
68 |
+
return attachment
|
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, start_time):
|
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 |
+
end_time = time.time()
|
90 |
+
total_time = end_time - start_time
|
91 |
+
|
92 |
+
await asyncio.gather(
|
93 |
+
ctx.send(f'{ctx.author.mention} Jojo image generated in {total_time:.2f} seconds.', file=discord.File(im)),
|
94 |
+
asyncio.sleep(0.5),
|
95 |
+
ctx.message.remove_reaction('β', bot.user),
|
96 |
+
asyncio.sleep(0.5),
|
97 |
+
ctx.message.add_reaction('β
')
|
98 |
+
)
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
|
105 |
#--------------------------------------------------------
|
106 |
def get_total_threads():
|
|
|
127 |
#--------------------------------------------------------
|
128 |
|
129 |
|
130 |
+
|
131 |
+
'''
|
132 |
+
async def discord_after(ctx, im):
|
133 |
+
await asyncio.gather(
|
134 |
+
ctx.send(f'{ctx.author.mention} Here is the jojo version of it'),
|
135 |
+
ctx.send(file=discord.File(im)),
|
136 |
+
ctx.message.remove_reaction('β', bot.user),
|
137 |
+
ctx.message.add_reaction('β
')
|
138 |
+
)
|
139 |
+
|
140 |
+
'''
|
141 |
+
|
142 |
+
|
143 |
+
'''
|
144 |
+
def blocking_io():
|
145 |
+
#generate
|
146 |
+
#return image
|
147 |
+
|
148 |
+
async def main():
|
149 |
+
loop = asyncio.get_running_loop()
|
150 |
+
|
151 |
+
|
152 |
+
|
153 |
+
exeresult = await loop.run_in_executor(
|
154 |
+
None, blocking_io)
|
155 |
+
print('default thread pool', exeresult)
|
156 |
+
|
157 |
+
'''
|