Synced repo using 'sync_with_huggingface' Github Action
Browse files- app.py +5 -2
- musicgen.py +4 -4
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import threading
|
3 |
|
4 |
import discord
|
@@ -92,10 +93,12 @@ async def deepfloydif(ctx, prompt: str):
|
|
92 |
|
93 |
@client.hybrid_command(name="musicgen", with_app_command=True, description="Enter a prompt to generate music!")
|
94 |
@app_commands.guilds(MY_GUILD)
|
95 |
-
async def musicgen(ctx, prompt: str):
|
96 |
"""Generates music based on a prompt"""
|
|
|
|
|
97 |
try:
|
98 |
-
await music_create(ctx, prompt)
|
99 |
except Exception as e:
|
100 |
print(f"Error: {e}")
|
101 |
|
|
|
1 |
import os
|
2 |
+
import random
|
3 |
import threading
|
4 |
|
5 |
import discord
|
|
|
93 |
|
94 |
@client.hybrid_command(name="musicgen", with_app_command=True, description="Enter a prompt to generate music!")
|
95 |
@app_commands.guilds(MY_GUILD)
|
96 |
+
async def musicgen(ctx, prompt: str, seed: int = None):
|
97 |
"""Generates music based on a prompt"""
|
98 |
+
if seed is None:
|
99 |
+
seed = random.randint(1, 10000)
|
100 |
try:
|
101 |
+
await music_create(ctx, prompt, seed)
|
102 |
except Exception as e:
|
103 |
print(f"Error: {e}")
|
104 |
|
musicgen.py
CHANGED
@@ -13,10 +13,10 @@ MUSIC_CHANNEL_ID = 1140990231730987058 # real musicgen channel
|
|
13 |
musicgen = Client("huggingface-projects/transformers-musicgen", hf_token=os.getenv("HF_TOKEN"))
|
14 |
|
15 |
|
16 |
-
def music_create_job(prompt):
|
17 |
"""Generates music based on a given prompt"""
|
18 |
try:
|
19 |
-
job = musicgen.submit(prompt, api_name="/predict")
|
20 |
while not job.done():
|
21 |
pass
|
22 |
return job
|
@@ -25,7 +25,7 @@ def music_create_job(prompt):
|
|
25 |
print(f"music_create_job Error: {e}")
|
26 |
|
27 |
|
28 |
-
async def music_create(ctx, prompt):
|
29 |
"""Runs music_create_job in executor"""
|
30 |
try:
|
31 |
if ctx.author.id != BOT_USER_ID:
|
@@ -44,7 +44,7 @@ async def music_create(ctx, prompt):
|
|
44 |
print("Running music_create_job...")
|
45 |
|
46 |
loop = asyncio.get_running_loop()
|
47 |
-
job = await loop.run_in_executor(None, music_create_job, prompt)
|
48 |
|
49 |
try:
|
50 |
job.result()
|
|
|
13 |
musicgen = Client("huggingface-projects/transformers-musicgen", hf_token=os.getenv("HF_TOKEN"))
|
14 |
|
15 |
|
16 |
+
def music_create_job(prompt, seed):
|
17 |
"""Generates music based on a given prompt"""
|
18 |
try:
|
19 |
+
job = musicgen.submit(prompt, seed, api_name="/predict")
|
20 |
while not job.done():
|
21 |
pass
|
22 |
return job
|
|
|
25 |
print(f"music_create_job Error: {e}")
|
26 |
|
27 |
|
28 |
+
async def music_create(ctx, prompt, seed):
|
29 |
"""Runs music_create_job in executor"""
|
30 |
try:
|
31 |
if ctx.author.id != BOT_USER_ID:
|
|
|
44 |
print("Running music_create_job...")
|
45 |
|
46 |
loop = asyncio.get_running_loop()
|
47 |
+
job = await loop.run_in_executor(None, music_create_job, prompt, seed)
|
48 |
|
49 |
try:
|
50 |
job.result()
|