lunarflu HF Staff commited on
Commit
7f0e43f
·
1 Parent(s): ac1b5ab

reorganized functions, added combined_image_path to the thread

Browse files
Files changed (1) hide show
  1. app.py +28 -32
app.py CHANGED
@@ -92,41 +92,14 @@ async def deepfloydif(ctx, *, prompt: str):
92
  combined_image_path = os.path.join(stage_1_results, 'combined_image.png')
93
  combined_image.save(combined_image_path)
94
 
95
- # Trigger the second stage prediction
96
- #await dfif2(ctx, stage_1_result_path)
97
-
98
-
99
-
100
-
101
-
102
- await create_thread_dfif(ctx)
103
 
104
 
105
  #with open(combined_image_path, 'rb') as f:
106
  # sent_message = await ctx.reply('Here is the combined image. React with the image number you want to upscale!', file=discord.File(f, 'combined_image.png'))
107
 
108
- # bot reacts with appropriate emojis to the post, both showing the user what options they have,
109
- # as well as showing which post to react to.
110
- for emoji in ['1️⃣', '2️⃣', '3️⃣', '4️⃣']:
111
- await sent_message.add_reaction(emoji)
112
-
113
- reaction, user = await bot.wait_for('reaction_add', check=check_reaction)
114
- if str(reaction.emoji) == '1️⃣':
115
- await ctx.reply("Upscaling the first image...")
116
- index = 0
117
- await dfif2(ctx, index, stage_1_result_path)
118
- elif str(reaction.emoji) == '2️⃣':
119
- await ctx.reply("Upscaling the second image...")
120
- index = 1
121
- await dfif2(ctx, index, stage_1_result_path)
122
- elif str(reaction.emoji) == '3️⃣':
123
- await ctx.reply("Upscaling the third image...")
124
- index = 2
125
- await dfif2(ctx, index, stage_1_result_path)
126
- elif str(reaction.emoji) == '4️⃣':
127
- await ctx.reply("Upscaling the fourth image...")
128
- index = 3
129
- await dfif2(ctx, index, stage_1_result_path)
130
 
131
  #deepfloydif try/except
132
  except Exception as e:
@@ -153,10 +126,33 @@ async def dfif2(ctx, index: int, stage_1_result_path):
153
  print(f"Error: {e}")
154
  await ctx.reply('An error occurred while processing stage 2 upscaling. Please try again later.')
155
  #----------------------------------------------------------------------------------------------------------------------------
156
- async def create_thread_dfif(ctx):
157
  with open(combined_image_path, 'rb') as f:
158
  thread_channel = await ctx.channel.create_thread(name='Image Thread')
159
- sent_message = await ctx.reply('Here is the combined image. React with the image number you want to upscale!', file=discord.File(f, 'combined_image.png'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  #----------------------------------------------------------------------------------------------------------------------------
161
 
162
 
 
92
  combined_image_path = os.path.join(stage_1_results, 'combined_image.png')
93
  combined_image.save(combined_image_path)
94
 
95
+ # creates a thread, passing the combined_image_path in
96
+ await create_thread_dfif(ctx, combined_image_path)
 
 
 
 
 
 
97
 
98
 
99
  #with open(combined_image_path, 'rb') as f:
100
  # sent_message = await ctx.reply('Here is the combined image. React with the image number you want to upscale!', file=discord.File(f, 'combined_image.png'))
101
 
102
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  #deepfloydif try/except
105
  except Exception as e:
 
126
  print(f"Error: {e}")
127
  await ctx.reply('An error occurred while processing stage 2 upscaling. Please try again later.')
128
  #----------------------------------------------------------------------------------------------------------------------------
129
+ async def create_thread_dfif(ctx, combined_image_path):
130
  with open(combined_image_path, 'rb') as f:
131
  thread_channel = await ctx.channel.create_thread(name='Image Thread')
132
+ sent_message = await ctx.reply('Here is the combined image. React with the image number you want to upscale!', file=discord.File(f, 'combined_image.png'))
133
+
134
+ # bot reacts with appropriate emojis to the post, both showing the user what options they have,
135
+ # as well as showing which post to react to.
136
+ for emoji in ['1️⃣', '2️⃣', '3️⃣', '4️⃣']:
137
+ await sent_message.add_reaction(emoji)
138
+
139
+ reaction, user = await bot.wait_for('reaction_add', check=check_reaction)
140
+ if str(reaction.emoji) == '1️⃣':
141
+ await ctx.reply("Upscaling the first image...")
142
+ index = 0
143
+ await dfif2(ctx, index, stage_1_result_path)
144
+ elif str(reaction.emoji) == '2️⃣':
145
+ await ctx.reply("Upscaling the second image...")
146
+ index = 1
147
+ await dfif2(ctx, index, stage_1_result_path)
148
+ elif str(reaction.emoji) == '3️⃣':
149
+ await ctx.reply("Upscaling the third image...")
150
+ index = 2
151
+ await dfif2(ctx, index, stage_1_result_path)
152
+ elif str(reaction.emoji) == '4️⃣':
153
+ await ctx.reply("Upscaling the fourth image...")
154
+ index = 3
155
+ await dfif2(ctx, index, stage_1_result_path)
156
  #----------------------------------------------------------------------------------------------------------------------------
157
 
158