[decorators] big test, custom path, individual image reacts
Browse files
app.py
CHANGED
@@ -19,6 +19,9 @@ from pytz import timezone
|
|
19 |
#
|
20 |
import asyncio
|
21 |
|
|
|
|
|
|
|
22 |
|
23 |
DFIF_TOKEN = os.getenv('HF_TOKEN')
|
24 |
df = Client("huggingface-projects/IF", DFIF_TOKEN)
|
@@ -44,8 +47,9 @@ async def on_ready():
|
|
44 |
async def deepfloydif(ctx, *, prompt: str):
|
45 |
try:
|
46 |
try:
|
47 |
-
|
48 |
-
|
|
|
49 |
|
50 |
await ctx.message.add_reaction('π')
|
51 |
thread = await ctx.message.create_thread(name=f'{ctx.author} Image Upscaling Thread ')
|
@@ -107,7 +111,7 @@ async def deepfloydif(ctx, *, prompt: str):
|
|
107 |
|
108 |
#----------------------------------------------------------------------------------------------------------------------------
|
109 |
# Stage 2
|
110 |
-
async def dfif2(
|
111 |
try:
|
112 |
selected_index_for_stage_2 = index
|
113 |
seed_2 = 0
|
@@ -119,9 +123,9 @@ async def dfif2(ctx, index: int, stage_1_result_path, thread):
|
|
119 |
|
120 |
|
121 |
with open(result_path, 'rb') as f:
|
122 |
-
await thread.send(f'
|
123 |
#await ctx.reply('Here is the result of the second stage', file=discord.File(f, 'result.png'))
|
124 |
-
await ctx.message.add_reaction('
|
125 |
|
126 |
|
127 |
|
@@ -131,7 +135,33 @@ async def dfif2(ctx, index: int, stage_1_result_path, thread):
|
|
131 |
await ctx.reply('An error occured in stage 2')
|
132 |
await ctx.message.add_reaction('β')
|
133 |
#----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
|
137 |
|
|
|
19 |
#
|
20 |
import asyncio
|
21 |
|
22 |
+
import shutil # for doing image movement magic
|
23 |
+
|
24 |
+
|
25 |
|
26 |
DFIF_TOKEN = os.getenv('HF_TOKEN')
|
27 |
df = Client("huggingface-projects/IF", DFIF_TOKEN)
|
|
|
47 |
async def deepfloydif(ctx, *, prompt: str):
|
48 |
try:
|
49 |
try:
|
50 |
+
channelcheck = bot.get_channel(channel_id)
|
51 |
+
if channelcheck != 1100458786826747945: # bot-test
|
52 |
+
return
|
53 |
|
54 |
await ctx.message.add_reaction('π')
|
55 |
thread = await ctx.message.create_thread(name=f'{ctx.author} Image Upscaling Thread ')
|
|
|
111 |
|
112 |
#----------------------------------------------------------------------------------------------------------------------------
|
113 |
# Stage 2
|
114 |
+
async def dfif2(index: int, stage_1_result_path, thread):
|
115 |
try:
|
116 |
selected_index_for_stage_2 = index
|
117 |
seed_2 = 0
|
|
|
123 |
|
124 |
|
125 |
with open(result_path, 'rb') as f:
|
126 |
+
await thread.send(f'Here is the upscaled image! :) ', file=discord.File(f, 'result.png'))
|
127 |
#await ctx.reply('Here is the result of the second stage', file=discord.File(f, 'result.png'))
|
128 |
+
#await ctx.message.add_reaction('β
') need to fix this
|
129 |
|
130 |
|
131 |
|
|
|
135 |
await ctx.reply('An error occured in stage 2')
|
136 |
await ctx.message.add_reaction('β')
|
137 |
#----------------------------------------------------------------------------------------------------------------------------
|
138 |
+
@bot.event
|
139 |
+
async def on_reaction_add(reaction, user):
|
140 |
+
# safety checks first
|
141 |
+
if user.bot:
|
142 |
+
return
|
143 |
+
|
144 |
+
# do they have the required (verified) role?
|
145 |
+
guild = reaction.message.guild
|
146 |
+
member = guild.get_member(user.id)
|
147 |
|
148 |
+
# Check if the user has the desired role
|
149 |
+
required_role_id = 897376942817419265 # huggingfolks for now
|
150 |
+
required_role = guild.get_role(required_role_id)
|
151 |
+
|
152 |
+
if required_role not in member.roles:
|
153 |
+
return
|
154 |
+
|
155 |
+
attachment = reaction.message.attachments[0]
|
156 |
+
emoji = reaction.emoji
|
157 |
+
|
158 |
+
if reaction.emoji.name == 'π':
|
159 |
+
if message.attachments:
|
160 |
+
if user.id == message.mentions[0].id: # all we care about is upscaling whatever image this is
|
161 |
+
stage_1_result_path = "/tmp/s1rp"
|
162 |
+
attachment_path = os.path.join(stage_1_result_path, attachment.filename)
|
163 |
+
await attachment.save(attachment_path)
|
164 |
+
await dfif2(0, attachment_path, thread=reaction.message.reference.resolved)
|
165 |
|
166 |
|
167 |
|