Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,24 +31,29 @@ class ModelManager:
|
|
| 31 |
cls._music_pipeline = pipeline("text-to-audio", "facebook/musicgen-small", device="cpu")
|
| 32 |
return cls._music_pipeline
|
| 33 |
|
| 34 |
-
# 8
|
| 35 |
-
|
| 36 |
-
"
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
-
async def band_consulting(user_input,
|
| 43 |
req_id = str(uuid.uuid4())[:8]
|
| 44 |
voice_path = f"/tmp/v_{req_id}.mp3"
|
| 45 |
music_path = f"/tmp/m_{req_id}.wav"
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
system_prompt = f"""You are {member_name}
|
| 51 |
-
You MUST respond ONLY in the language: {consult_lang}.
|
| 52 |
Provide 5-7 lines of professional music advice.
|
| 53 |
[TAB] Section: Detailed chords/tabs.
|
| 54 |
[MUSIC] Section: English prompt reflecting: {jam_context}"""
|
|
@@ -71,17 +76,17 @@ async def band_consulting(user_input, member_name, consult_lang, g_inst, b_inst,
|
|
| 71 |
|
| 72 |
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 73 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 74 |
-
tab_display = tab_match.group(1).strip() if tab_match else "No
|
| 75 |
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL | re.IGNORECASE)
|
| 76 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text, flags=re.IGNORECASE).strip()
|
| 77 |
|
| 78 |
-
# TTS
|
| 79 |
-
|
| 80 |
-
communicate = edge_tts.Communicate(re.sub(r'[\*\#\-\_\~\|]', '', clean_text), voice_name)
|
| 81 |
await communicate.save(voice_path)
|
| 82 |
|
|
|
|
| 83 |
music_gen = ModelManager.get_music()
|
| 84 |
-
music_p = music_match.group(1).strip() if music_match else "rock guitar
|
| 85 |
music_output = music_gen(music_p, forward_params={"max_new_tokens": 512})
|
| 86 |
audio_data = np.squeeze(music_output["audio"])
|
| 87 |
audio_int16 = (audio_data * 32767).astype(np.int16)
|
|
@@ -90,7 +95,8 @@ async def band_consulting(user_input, member_name, consult_lang, g_inst, b_inst,
|
|
| 90 |
return clean_text, voice_path, music_path, tab_display
|
| 91 |
|
| 92 |
with gr.Blocks() as demo:
|
| 93 |
-
|
|
|
|
| 94 |
outputs = [gr.Textbox(visible=False), gr.Audio(visible=False), gr.Audio(visible=False), gr.Textbox(visible=False)]
|
| 95 |
btn = gr.Button("API", visible=False)
|
| 96 |
btn.click(band_consulting, inputs, outputs, api_name="predict")
|
|
|
|
| 31 |
cls._music_pipeline = pipeline("text-to-audio", "facebook/musicgen-small", device="cpu")
|
| 32 |
return cls._music_pipeline
|
| 33 |
|
| 34 |
+
# 8๊ฐ ์ธ์ด๋ณ ์ ๋ด ๋ฉค๋ฒ ๋ฐ ๋ณด์ด์ค ์ค์
|
| 35 |
+
LANG_MEMBER_MAP = {
|
| 36 |
+
"Korean": {"name": "์์ค (Korea)", "voice": "ko-KR-SunHiNeural"},
|
| 37 |
+
"English": {"name": "Chloe (USA)", "voice": "en-US-AriaNeural"},
|
| 38 |
+
"Japanese": {"name": "Naomi (Japan)", "voice": "ja-JP-NanamiNeural"},
|
| 39 |
+
"Portuguese": {"name": "Beatrice (Brazil)", "voice": "pt-BR-FranciscaNeural"},
|
| 40 |
+
"Spanish": {"name": "Elena (Spain)", "voice": "es-ES-ElviraNeural"},
|
| 41 |
+
"Arabic": {"name": "Amira (Egypt)", "voice": "ar-EG-SalmaNeural"},
|
| 42 |
+
"Chinese": {"name": "Liwei (China)", "voice": "zh-CN-XiaoxiaoNeural"},
|
| 43 |
+
"French": {"name": "Sophie (France)", "voice": "fr-FR-DeniseNeural"}
|
| 44 |
}
|
| 45 |
|
| 46 |
+
async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, chords):
|
| 47 |
req_id = str(uuid.uuid4())[:8]
|
| 48 |
voice_path = f"/tmp/v_{req_id}.mp3"
|
| 49 |
music_path = f"/tmp/m_{req_id}.wav"
|
| 50 |
|
| 51 |
+
# ์ ํ๋ ์ธ์ด์ ๋ฐ๋ฅธ ๋ฉค๋ฒ ์๋ ๋งค์นญ
|
| 52 |
+
member_info = LANG_MEMBER_MAP.get(selected_lang, LANG_MEMBER_MAP["Korean"])
|
| 53 |
+
member_name = member_info["name"]
|
| 54 |
|
| 55 |
+
jam_context = f"Guitar: {g_inst}, Bass: {b_inst}, Drums: {d_inst}, Chords: {chords}"
|
| 56 |
+
system_prompt = f"""You are {member_name}. You MUST respond ONLY in {selected_lang}.
|
|
|
|
| 57 |
Provide 5-7 lines of professional music advice.
|
| 58 |
[TAB] Section: Detailed chords/tabs.
|
| 59 |
[MUSIC] Section: English prompt reflecting: {jam_context}"""
|
|
|
|
| 76 |
|
| 77 |
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 78 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 79 |
+
tab_display = tab_match.group(1).strip() if tab_match else "No Data"
|
| 80 |
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL | re.IGNORECASE)
|
| 81 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text, flags=re.IGNORECASE).strip()
|
| 82 |
|
| 83 |
+
# TTS ์์ฑ
|
| 84 |
+
communicate = edge_tts.Communicate(re.sub(r'[\*\#\-\_\~\|]', '', clean_text), member_info["voice"])
|
|
|
|
| 85 |
await communicate.save(voice_path)
|
| 86 |
|
| 87 |
+
# MusicGen ์์ฑ (12์ด)
|
| 88 |
music_gen = ModelManager.get_music()
|
| 89 |
+
music_p = music_match.group(1).strip() if music_match else "rock guitar"
|
| 90 |
music_output = music_gen(music_p, forward_params={"max_new_tokens": 512})
|
| 91 |
audio_data = np.squeeze(music_output["audio"])
|
| 92 |
audio_int16 = (audio_data * 32767).astype(np.int16)
|
|
|
|
| 95 |
return clean_text, voice_path, music_path, tab_display
|
| 96 |
|
| 97 |
with gr.Blocks() as demo:
|
| 98 |
+
# ํ๋ผ๋ฏธํฐ 6๊ฐ (์๋ด๋ด์ฉ, ์๋ด์ธ์ด, ๊ธฐํ, ๋ฒ ์ด์ค, ๋๋ผ, ์ฝ๋)
|
| 99 |
+
inputs = [gr.Textbox(visible=False) for _ in range(6)]
|
| 100 |
outputs = [gr.Textbox(visible=False), gr.Audio(visible=False), gr.Audio(visible=False), gr.Textbox(visible=False)]
|
| 101 |
btn = gr.Button("API", visible=False)
|
| 102 |
btn.click(band_consulting, inputs, outputs, api_name="predict")
|