Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -27,8 +27,62 @@ import mutagen
|
|
27 |
from mutagen.mp3 import MP3
|
28 |
from mutagen.wave import WAVE
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
img_to_text = gr.Blocks.load(name="spaces/fffiloni/CLIP-Interrogator-2")
|
31 |
-
text_to_music = gr.Interface.load("spaces/fffiloni/text-2-music")
|
32 |
|
33 |
language_translation_model = hub.Module(name='baidu_translate')
|
34 |
language_recognition_model = hub.Module(name='baidu_language_recognition')
|
@@ -123,7 +177,8 @@ def get_music(prompt, musicAI_indx, duration):
|
|
123 |
wavfile.export(mp3file_name, format="mp3")
|
124 |
return spec, mp3file_name
|
125 |
else:
|
126 |
-
result = text_to_music(prompt, fn_index=0)
|
|
|
127 |
|
128 |
print(f"""—————
|
129 |
NEW RESULTS
|
|
|
27 |
from mutagen.mp3 import MP3
|
28 |
from mutagen.wave import WAVE
|
29 |
|
30 |
+
|
31 |
+
import time
|
32 |
+
import base64
|
33 |
+
import gradio as gr
|
34 |
+
from sentence_transformers import SentenceTransformer
|
35 |
+
|
36 |
+
import httpx
|
37 |
+
import json
|
38 |
+
|
39 |
+
from utils import get_tags_for_prompts, get_mubert_tags_embeddings, get_pat
|
40 |
+
|
41 |
+
minilm = SentenceTransformer('all-MiniLM-L6-v2')
|
42 |
+
mubert_tags_embeddings = get_mubert_tags_embeddings(minilm)
|
43 |
+
|
44 |
+
|
45 |
+
def get_track_by_tags(tags, pat, duration, maxit=20, loop=False):
|
46 |
+
if loop:
|
47 |
+
mode = "loop"
|
48 |
+
else:
|
49 |
+
mode = "track"
|
50 |
+
r = httpx.post('https://api-b2b.mubert.com/v2/RecordTrackTTM',
|
51 |
+
json={
|
52 |
+
"method": "RecordTrackTTM",
|
53 |
+
"params": {
|
54 |
+
"pat": pat,
|
55 |
+
"duration": duration,
|
56 |
+
"tags": tags,
|
57 |
+
"mode": mode
|
58 |
+
}
|
59 |
+
})
|
60 |
+
|
61 |
+
rdata = json.loads(r.text)
|
62 |
+
assert rdata['status'] == 1, rdata['error']['text']
|
63 |
+
trackurl = rdata['data']['tasks'][0]['download_link']
|
64 |
+
|
65 |
+
print('Generating track ', end='')
|
66 |
+
for i in range(maxit):
|
67 |
+
r = httpx.get(trackurl)
|
68 |
+
if r.status_code == 200:
|
69 |
+
return trackurl
|
70 |
+
time.sleep(1)
|
71 |
+
|
72 |
+
|
73 |
+
def generate_track_by_prompt(prompt):
|
74 |
+
try:
|
75 |
+
pat = get_pat("[email protected]")
|
76 |
+
_, tags = get_tags_for_prompts(minilm, mubert_tags_embeddings, [prompt, ])[0]
|
77 |
+
result = get_track_by_tags(tags, pat, int(30), loop=False)
|
78 |
+
print(result)
|
79 |
+
return result
|
80 |
+
except Exception as e:
|
81 |
+
return str(e)
|
82 |
+
|
83 |
+
|
84 |
img_to_text = gr.Blocks.load(name="spaces/fffiloni/CLIP-Interrogator-2")
|
85 |
+
#text_to_music = gr.Interface.load("spaces/fffiloni/text-2-music")
|
86 |
|
87 |
language_translation_model = hub.Module(name='baidu_translate')
|
88 |
language_recognition_model = hub.Module(name='baidu_language_recognition')
|
|
|
177 |
wavfile.export(mp3file_name, format="mp3")
|
178 |
return spec, mp3file_name
|
179 |
else:
|
180 |
+
#result = text_to_music(prompt, fn_index=0)
|
181 |
+
result = generate_track_by_prompt(prompt)
|
182 |
|
183 |
print(f"""—————
|
184 |
NEW RESULTS
|