lunarflu HF Staff commited on
Commit
08fb6c7
·
1 Parent(s): e7f9a55

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (2) hide show
  1. app.py +1 -0
  2. musicgen.py +17 -9
app.py CHANGED
@@ -105,4 +105,5 @@ with gr.Blocks() as demo:
105
  Currently supported models are Falcon and DeepfloydIF
106
  """)
107
  demo.queue(concurrency_count=100)
 
108
  demo.launch()
 
105
  Currently supported models are Falcon and DeepfloydIF
106
  """)
107
  demo.queue(concurrency_count=100)
108
+ demo.queue(max_size=100)
109
  demo.launch()
musicgen.py CHANGED
@@ -1,11 +1,14 @@
1
- import asyncio
2
  import os
3
 
 
4
  import discord
 
5
  from gradio_client import Client
 
 
6
 
7
  BOT_USER_ID = 1102236653545861151 # real
8
- MUSIC_CHANNEL_ID = 1140990231730987058 # real
9
 
10
  musicgen = Client("huggingface-projects/transformers-musicgen", hf_token=os.getenv("HF_TOKEN"))
11
 
@@ -16,10 +19,7 @@ def music_create_job(prompt):
16
  job = musicgen.submit(prompt, api_name="/predict")
17
  while not job.done():
18
  pass
19
- files = job.outputs()
20
- files = files[0]
21
-
22
- return files
23
 
24
  except Exception as e:
25
  print(f"music_create_job Error: {e}")
@@ -48,9 +48,17 @@ async def music_create(ctx, prompt):
48
  print("Running music_create_job...")
49
 
50
  loop = asyncio.get_running_loop()
51
- files = await loop.run_in_executor(None, music_create_job, prompt)
 
 
 
 
 
 
 
52
 
53
- audio, video = files[0], files[1]
 
54
 
55
  with open(audio, "rb") as file:
56
  discord_file = discord.File(file)
@@ -65,7 +73,7 @@ async def music_create(ctx, prompt):
65
  tweet1 = "https://twitter.com/intent/tweet?text="
66
  tweet2 = "I%20generated%20this%20audio%20using%20MusicGen"
67
  tweet3 = "%20in%20the%20%F0%9F%A4%97%20@huggingface%20Discord!"
68
- tweet4 = "%0Ahf.co/join/discord%0A%0APrompt:%20"
69
  prompt = prompt.replace(" ", "%20")
70
  intent_link = f"{tweet1}{tweet2}{tweet3}{tweet4}{prompt}"
71
  embed.add_field(
 
 
1
  import os
2
 
3
+ import asyncio
4
  import discord
5
+
6
  from gradio_client import Client
7
+ from gradio_client.utils import QueueError
8
+
9
 
10
  BOT_USER_ID = 1102236653545861151 # real
11
+ MUSIC_CHANNEL_ID = 1140990231730987058 # real musicgen channel
12
 
13
  musicgen = Client("huggingface-projects/transformers-musicgen", hf_token=os.getenv("HF_TOKEN"))
14
 
 
19
  job = musicgen.submit(prompt, api_name="/predict")
20
  while not job.done():
21
  pass
22
+ return job
 
 
 
23
 
24
  except Exception as e:
25
  print(f"music_create_job Error: {e}")
 
48
  print("Running music_create_job...")
49
 
50
  loop = asyncio.get_running_loop()
51
+ job = await loop.run_in_executor(None, music_create_job, prompt)
52
+
53
+ try:
54
+ job.result()
55
+ files = job.outputs()
56
+ media_files = files[0]
57
+ except QueueError:
58
+ await thread.send("The gradio space powering this bot is really busy! Please try again later!")
59
 
60
+ audio = media_files[0]
61
+ video = media_files[1]
62
 
63
  with open(audio, "rb") as file:
64
  discord_file = discord.File(file)
 
73
  tweet1 = "https://twitter.com/intent/tweet?text="
74
  tweet2 = "I%20generated%20this%20audio%20using%20MusicGen"
75
  tweet3 = "%20in%20the%20%F0%9F%A4%97%20@huggingface%20Discord!"
76
+ tweet4 = "%0Ahf.co/join/discord%0APrompt:%20"
77
  prompt = prompt.replace(" ", "%20")
78
  intent_link = f"{tweet1}{tweet2}{tweet3}{tweet4}{prompt}"
79
  embed.add_field(