lunarflu HF Staff commited on
Commit
bf54bc6
·
1 Parent(s): 0615999

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -19,7 +19,7 @@ import concurrent.futures
19
  import multiprocessing
20
 
21
 
22
- semaphore = asyncio.Semaphore(4)
23
 
24
  DFIF_TOKEN = os.getenv('HF_TOKEN')
25
  DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
@@ -48,7 +48,9 @@ async def jojo(ctx):
48
  start_time = time.time()
49
  attachment = await discord_before(ctx)
50
  if attachment:
 
51
  asyncio.create_task(generation(ctx, attachment, start_time))
 
52
  #await generation(ctx, attachment)
53
 
54
  async def discord_before(ctx):
@@ -77,8 +79,8 @@ async def discord_before(ctx):
77
  async def generation(ctx, attachment, start_time):
78
  if attachment:
79
  style = 'JoJo'
80
- async with semaphore:
81
- im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
82
  #im = await asyncio.to_thread(jojogan.predict, attachment.url, style)
83
  #im = jojogan.predict(attachment.url, style)
84
 
@@ -97,7 +99,7 @@ async def generation(ctx, attachment, start_time):
97
  asyncio.sleep(0.5),
98
  ctx.message.add_reaction('✅')
99
  )
100
-
101
 
102
 
103
 
 
19
  import multiprocessing
20
 
21
 
22
+ semaphore = Semaphore(4)
23
 
24
  DFIF_TOKEN = os.getenv('HF_TOKEN')
25
  DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
 
48
  start_time = time.time()
49
  attachment = await discord_before(ctx)
50
  if attachment:
51
+ semaphore.acquire()
52
  asyncio.create_task(generation(ctx, attachment, start_time))
53
+ semaphore.release()
54
  #await generation(ctx, attachment)
55
 
56
  async def discord_before(ctx):
 
79
  async def generation(ctx, attachment, start_time):
80
  if attachment:
81
  style = 'JoJo'
82
+
83
+ im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
84
  #im = await asyncio.to_thread(jojogan.predict, attachment.url, style)
85
  #im = jojogan.predict(attachment.url, style)
86
 
 
99
  asyncio.sleep(0.5),
100
  ctx.message.add_reaction('✅')
101
  )
102
+
103
 
104
 
105