lunarflu HF staff commited on
Commit
2864257
1 Parent(s): 5e35a5d

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (1) hide show
  1. wuerstchen.py +8 -11
wuerstchen.py CHANGED
@@ -14,7 +14,8 @@ BOT_USER_ID = 1102236653545861151
14
  WUERSTCHEN_CHANNEL_ID = 1151792944676864041
15
 
16
 
17
- def wuerstchen_inference(prompt, client):
 
18
  negative_prompt = ""
19
  seed = random.randint(0, 1000)
20
  width = 1024
@@ -25,7 +26,7 @@ def wuerstchen_inference(prompt, client):
25
  decoder_guidance_scale = 0
26
  num_images_per_prompt = 1
27
 
28
- job = wuerstchen_client.submit(
29
  prompt,
30
  negative_prompt,
31
  seed,
@@ -38,14 +39,12 @@ def wuerstchen_inference(prompt, client):
38
  num_images_per_prompt,
39
  api_name="/run",
40
  )
41
- while not job.done():
42
- pass
43
- else:
44
- return job
45
 
46
 
47
  async def run_wuerstchen(ctx, prompt, client):
48
- """wuerstchen"""
49
  try:
50
  if ctx.author.id != BOT_USER_ID:
51
  if ctx.channel.id == WUERSTCHEN_CHANNEL_ID:
@@ -53,12 +52,10 @@ async def run_wuerstchen(ctx, prompt, client):
53
  message = await ctx.send(f"**{prompt}** - {ctx.author.mention} <a:loading:1114111677990981692>")
54
 
55
  loop = asyncio.get_running_loop()
56
- job = await loop.run_in_executor(None, wuerstchen_inference, prompt, client)
57
 
58
- png_files = list(glob.glob(f"{job.outputs()[-1]}/**/*.png"))
59
  await message.delete()
60
-
61
- with open(png_files[0], "rb") as f:
62
  await channel.send(f"**{prompt}** - {ctx.author.mention}", file=discord.File(f, "wuerstchen.png"))
63
  except Exception as e:
64
  print(f"Error: {e}")
 
14
  WUERSTCHEN_CHANNEL_ID = 1151792944676864041
15
 
16
 
17
+ def wuerstchen_inference(prompt):
18
+ """Inference for Wuerstchen"""
19
  negative_prompt = ""
20
  seed = random.randint(0, 1000)
21
  width = 1024
 
26
  decoder_guidance_scale = 0
27
  num_images_per_prompt = 1
28
 
29
+ result_path = wuerstchen_client.predict(
30
  prompt,
31
  negative_prompt,
32
  seed,
 
39
  num_images_per_prompt,
40
  api_name="/run",
41
  )
42
+ png_file = list(glob.glob(f"{result_path}/**/*.png"))
43
+ return png_file[0]
 
 
44
 
45
 
46
  async def run_wuerstchen(ctx, prompt, client):
47
+ """Responds to /Wuerstchen command"""
48
  try:
49
  if ctx.author.id != BOT_USER_ID:
50
  if ctx.channel.id == WUERSTCHEN_CHANNEL_ID:
 
52
  message = await ctx.send(f"**{prompt}** - {ctx.author.mention} <a:loading:1114111677990981692>")
53
 
54
  loop = asyncio.get_running_loop()
55
+ result_path = await loop.run_in_executor(None, wuerstchen_inference, prompt)
56
 
 
57
  await message.delete()
58
+ with open(result_path, "rb") as f:
 
59
  await channel.send(f"**{prompt}** - {ctx.author.mention}", file=discord.File(f, "wuerstchen.png"))
60
  except Exception as e:
61
  print(f"Error: {e}")