lunarflu HF Staff commited on
Commit
0ee5086
·
1 Parent(s): 8b33266

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -16
app.py CHANGED
@@ -9,7 +9,6 @@ import gradio as gr
9
  import discord
10
  from gradio_client import Client
11
  from PIL import Image
12
- from discord import app_commands
13
  from discord.ext import commands
14
 
15
  from discord.ui import Button, View
@@ -17,18 +16,18 @@ from discord.ui import Button, View
17
  HF_TOKEN = os.getenv("HF_TOKEN")
18
  deepfloydif_client = Client("huggingface-projects/IF", HF_TOKEN)
19
  DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
20
-
21
- #---------------------------------------------------------------------------------------------------------------------
22
  intents = discord.Intents.all()
23
  bot = commands.Bot(command_prefix="/", intents=intents)
24
- #---------------------------------------------------------------------------------------------------------------------
 
25
  @bot.event
26
  async def on_ready():
27
  print(f"Logged in as {bot.user} (ID: {bot.user.id})")
28
  synced = await bot.tree.sync()
29
  print(f"Synced commands: {', '.join([s.name for s in synced])}.")
30
  print("------")
31
- #---------------------------------------------------------------------------------------------------------------------
 
32
  @bot.hybrid_command(
33
  name="deepfloydif",
34
  description="Enter a prompt to generate an image! Can generate realistic text, too!",
@@ -41,7 +40,6 @@ async def deepfloydif(ctx, prompt: str):
41
  print(f"Error: {e}")
42
 
43
 
44
-
45
  def deepfloydif_generate64_inference(prompt):
46
  """Generates four images based on a prompt"""
47
  negative_prompt = ""
@@ -139,9 +137,6 @@ def combine_images(png_files, stage_1_images, partial_path):
139
  return combined_image_path
140
 
141
 
142
-
143
-
144
-
145
  async def deepfloydif_generate64(ctx, prompt):
146
  """DeepfloydIF command (generate images with realistic text using slash commands)"""
147
  try:
@@ -188,9 +183,7 @@ async def deepfloydif_generate64(ctx, prompt):
188
 
189
  # create and use upscale 1024 button
190
  with open(result_path, "rb") as f:
191
- upscale1024 = Button(
192
- label="High-quality upscale (x4)", custom_id=str(index)
193
- ) # "0", "1" etc
194
  upscale1024.callback = upscale1024_callback
195
  view = View(timeout=None)
196
  view.add_item(upscale1024)
@@ -233,8 +226,7 @@ async def deepfloydif_generate64(ctx, prompt):
233
 
234
  # could store this message as combined_image_dfif in case it's useful for future testing
235
  await channel.send(
236
- f"**{prompt}** - {ctx.author.mention} Click a button to upscale! (make larger + enhance"
237
- " quality)",
238
  file=discord.File(f, f"{partial_path}.png"),
239
  view=view,
240
  )
@@ -271,7 +263,6 @@ async def deepfloydif_upscale1024(index: int, path_for_upscale256_upscaling, pro
271
  print(f"Error: {e}")
272
 
273
 
274
- #---------------------------------------------------------------------------------------------------------------------
275
  def run_bot():
276
  bot.run(DISCORD_TOKEN)
277
 
@@ -286,4 +277,4 @@ with gr.Blocks() as demo:
286
  """)
287
  demo.queue(concurrency_count=100)
288
  demo.queue(max_size=100)
289
- demo.launch()
 
9
  import discord
10
  from gradio_client import Client
11
  from PIL import Image
 
12
  from discord.ext import commands
13
 
14
  from discord.ui import Button, View
 
16
  HF_TOKEN = os.getenv("HF_TOKEN")
17
  deepfloydif_client = Client("huggingface-projects/IF", HF_TOKEN)
18
  DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
 
 
19
  intents = discord.Intents.all()
20
  bot = commands.Bot(command_prefix="/", intents=intents)
21
+
22
+
23
  @bot.event
24
  async def on_ready():
25
  print(f"Logged in as {bot.user} (ID: {bot.user.id})")
26
  synced = await bot.tree.sync()
27
  print(f"Synced commands: {', '.join([s.name for s in synced])}.")
28
  print("------")
29
+
30
+
31
  @bot.hybrid_command(
32
  name="deepfloydif",
33
  description="Enter a prompt to generate an image! Can generate realistic text, too!",
 
40
  print(f"Error: {e}")
41
 
42
 
 
43
  def deepfloydif_generate64_inference(prompt):
44
  """Generates four images based on a prompt"""
45
  negative_prompt = ""
 
137
  return combined_image_path
138
 
139
 
 
 
 
140
  async def deepfloydif_generate64(ctx, prompt):
141
  """DeepfloydIF command (generate images with realistic text using slash commands)"""
142
  try:
 
183
 
184
  # create and use upscale 1024 button
185
  with open(result_path, "rb") as f:
186
+ upscale1024 = Button(label="High-quality upscale (x4)", custom_id=str(index))
 
 
187
  upscale1024.callback = upscale1024_callback
188
  view = View(timeout=None)
189
  view.add_item(upscale1024)
 
226
 
227
  # could store this message as combined_image_dfif in case it's useful for future testing
228
  await channel.send(
229
+ f"**{prompt}** - {ctx.author.mention} Click a button to upscale! (make larger + enhance quality)",
 
230
  file=discord.File(f, f"{partial_path}.png"),
231
  view=view,
232
  )
 
263
  print(f"Error: {e}")
264
 
265
 
 
266
  def run_bot():
267
  bot.run(DISCORD_TOKEN)
268
 
 
277
  """)
278
  demo.queue(concurrency_count=100)
279
  demo.queue(max_size=100)
280
+ demo.launch()