lunarflu HF staff commited on
Commit
6ee42a9
1 Parent(s): 8032726

client = await loop.run_in_executor(None, get_client, None)

Browse files
Files changed (1) hide show
  1. app.py +17 -29
app.py CHANGED
@@ -63,45 +63,33 @@ async def music_create(ctx, prompt, seed):
63
  message = await ctx.send(f"**{prompt}** - {ctx.author.mention} Generating...")
64
 
65
  loop = asyncio.get_running_loop()
66
- job = await loop.run_in_executor(None, music_create_job, prompt, seed)
 
 
67
 
68
  try:
69
  job.result()
70
  files = job.outputs()
71
  media_files = files[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  except QueueError:
73
  await ctx.send("The gradio space powering this bot is really busy! Please try again later!")
74
 
75
- audio = media_files[0]
76
- video = media_files[1]
77
- short_filename = prompt[:20]
78
- audio_filename = f"{short_filename}.mp3"
79
- video_filename = f"{short_filename}.mp4"
80
-
81
- with open(video, "rb") as file:
82
- discord_video_file = discord.File(file, filename=video_filename)
83
- await ctx.send(file=discord_video_file)
84
-
85
- with open(audio, "rb") as file:
86
- discord_audio_file = discord.File(file, filename=audio_filename)
87
- await ctx.send(file=discord_audio_file)
88
-
89
  except Exception as e:
90
  print(f"music_create Error: {e}")
91
-
92
-
93
- def music_create_job(prompt, seed):
94
- """Generates music based on a given prompt"""
95
- try:
96
- job = musicgen.submit(prompt, seed, api_name="/predict")
97
- while not job.done():
98
- pass
99
- return job
100
-
101
- except Exception as e:
102
- print(f"music_create_job Error: {e}")
103
-
104
-
105
  #---------------------------------------------------------------------
106
  def run_bot():
107
  if not DISCORD_TOKEN:
 
63
  message = await ctx.send(f"**{prompt}** - {ctx.author.mention} Generating...")
64
 
65
  loop = asyncio.get_running_loop()
66
+ client = await loop.run_in_executor(None, get_client, None)
67
+ job = client.submit(prompt, seed, api_name="/predict")
68
+ await wait(job)
69
 
70
  try:
71
  job.result()
72
  files = job.outputs()
73
  media_files = files[0]
74
+ audio = media_files[0]
75
+ video = media_files[1]
76
+ short_filename = prompt[:20]
77
+ audio_filename = f"{short_filename}.mp3"
78
+ video_filename = f"{short_filename}.mp4"
79
+
80
+ with open(video, "rb") as file:
81
+ discord_video_file = discord.File(file, filename=video_filename)
82
+ await ctx.send(file=discord_video_file)
83
+
84
+ with open(audio, "rb") as file:
85
+ discord_audio_file = discord.File(file, filename=audio_filename)
86
+ await ctx.send(file=discord_audio_file)
87
+
88
  except QueueError:
89
  await ctx.send("The gradio space powering this bot is really busy! Please try again later!")
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  except Exception as e:
92
  print(f"music_create Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  #---------------------------------------------------------------------
94
  def run_bot():
95
  if not DISCORD_TOKEN: