Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ class ModelManager:
|
|
| 31 |
cls._music_pipeline = pipeline("text-to-audio", "facebook/musicgen-small", device="cpu")
|
| 32 |
return cls._music_pipeline
|
| 33 |
|
| 34 |
-
#
|
| 35 |
LANG_MEMBER_MAP = {
|
| 36 |
"Korean": {"name": "์์ค (Korea)", "voice": "ko-KR-SunHiNeural"},
|
| 37 |
"English": {"name": "Chloe (USA)", "voice": "en-US-AriaNeural"},
|
|
@@ -48,15 +48,12 @@ async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, cho
|
|
| 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 |
-
|
| 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: {
|
| 60 |
|
| 61 |
ai_text_raw = ""
|
| 62 |
groq_client = ModelManager.get_groq()
|
|
@@ -76,17 +73,15 @@ async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, cho
|
|
| 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
|
| 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,7 +90,6 @@ async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, cho
|
|
| 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)
|
|
|
|
| 31 |
cls._music_pipeline = pipeline("text-to-audio", "facebook/musicgen-small", device="cpu")
|
| 32 |
return cls._music_pipeline
|
| 33 |
|
| 34 |
+
# ์ธ์ด๋ณ ์ ๋ด ๋ฉค๋ฒ ์ค์
|
| 35 |
LANG_MEMBER_MAP = {
|
| 36 |
"Korean": {"name": "์์ค (Korea)", "voice": "ko-KR-SunHiNeural"},
|
| 37 |
"English": {"name": "Chloe (USA)", "voice": "en-US-AriaNeural"},
|
|
|
|
| 48 |
voice_path = f"/tmp/v_{req_id}.mp3"
|
| 49 |
music_path = f"/tmp/m_{req_id}.wav"
|
| 50 |
|
|
|
|
| 51 |
member_info = LANG_MEMBER_MAP.get(selected_lang, LANG_MEMBER_MAP["Korean"])
|
|
|
|
| 52 |
|
| 53 |
+
system_prompt = f"""You are {member_info['name']}. Respond ONLY in {selected_lang}.
|
|
|
|
| 54 |
Provide 5-7 lines of professional music advice.
|
| 55 |
[TAB] Section: Detailed chords/tabs.
|
| 56 |
+
[MUSIC] Section: English prompt reflecting: Guitar:{g_inst}, Bass:{b_inst}, Drums:{d_inst}, Chords:{chords}"""
|
| 57 |
|
| 58 |
ai_text_raw = ""
|
| 59 |
groq_client = ModelManager.get_groq()
|
|
|
|
| 73 |
|
| 74 |
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 75 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 76 |
+
tab_display = tab_match.group(1).strip() if tab_match else "No Score Data"
|
| 77 |
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL | re.IGNORECASE)
|
| 78 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text, flags=re.IGNORECASE).strip()
|
| 79 |
|
|
|
|
| 80 |
communicate = edge_tts.Communicate(re.sub(r'[\*\#\-\_\~\|]', '', clean_text), member_info["voice"])
|
| 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"
|
| 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 |
return clean_text, voice_path, music_path, tab_display
|
| 91 |
|
| 92 |
with gr.Blocks() as demo:
|
|
|
|
| 93 |
inputs = [gr.Textbox(visible=False) for _ in range(6)]
|
| 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)
|