Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,9 +32,9 @@ class ModelManager:
|
|
| 32 |
cls._music_pipeline = pipeline("text-to-audio", "facebook/musicgen-small", device="cpu")
|
| 33 |
return cls._music_pipeline
|
| 34 |
|
| 35 |
-
# ๋ฉค๋ฒ
|
| 36 |
PERSONA_MAP = {
|
| 37 |
-
"์์ค (Korea)": "์์ ์ ์ด๋ฉด์๋ ๊ฐ๋ ฌํ K-Rock ๋ฆฌ๋. ์ง์งํ๊ณ
|
| 38 |
"Chloe (USA)": "์์ ๋ถ๋ฐฉํ ์บ๋ฆฌํฌ๋์ ํํฌ ๋ฝ์คํ. ๊ฑฐ์นจ์๊ณ ์ฟจํ๋ฉฐ ์๋์ ํฑํ ๋งํฌ.",
|
| 39 |
"Naomi (Japan)": "์๋ฒฝ์ฃผ์ J-Rock ๊ธฐํ๋ฆฌ์คํธ. ์ฌ์ธํ๊ณ ์์ ๋ฐ๋ฅด๋ฉฐ ์์
์ด๋ก ์ ๋ ์นด๋ก์.",
|
| 40 |
"Beatrice (Brazil)": "์ด์ ์ ์ธ ์ผ๋ฐ ๋ฝ์ปค. ๊ธ์ ์ ์ด๊ณ ๋ฆฌ๋ฌ๊ฐ์ด ๋์น๋ฉฐ ์ธ์์ ์ฆ๊ฑฐ์์ ๊ฐ์กฐํจ.",
|
|
@@ -44,7 +44,6 @@ PERSONA_MAP = {
|
|
| 44 |
"Sophie (France)": "์์ ์ ์์กด์ฌ์ด ๊ฐํ ์๋ฐฉ๊ฐ๋ฅด๋ ๋ฝ์ปค. ์์ ์ด๊ณ ์ธ๋ จ๋ ํํ์ ์ฆ๊ฒจ ์."
|
| 45 |
}
|
| 46 |
|
| 47 |
-
# ์ธ์ด๋ณ ๋ฉค๋ฒ/๋ณด์ด์ค ๋งคํ
|
| 48 |
LANG_MEMBER_MAP = {
|
| 49 |
"Korean": {"name": "์์ค (Korea)", "voice": "ko-KR-SunHiNeural"},
|
| 50 |
"English": {"name": "Chloe (USA)", "voice": "en-US-AriaNeural"},
|
|
@@ -65,18 +64,18 @@ async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, cho
|
|
| 65 |
m_info = LANG_MEMBER_MAP.get(selected_lang, LANG_MEMBER_MAP["Korean"])
|
| 66 |
persona = PERSONA_MAP.get(m_info['name'], "์ด์ ์ ์ธ ๋ฝ์คํ")
|
| 67 |
|
| 68 |
-
# [์
|
| 69 |
system_prompt = f"""You are the rock star '{m_info['name']}'. Respond ONLY in {selected_lang}.
|
| 70 |
Persona: {persona}.
|
| 71 |
|
| 72 |
CRITICAL RULES:
|
| 73 |
-
1.
|
| 74 |
-
2. [TAB] SECTION:
|
| 75 |
-
-
|
| 76 |
-
-
|
| 77 |
-
-
|
| 78 |
-
3. [TRANSLATION]: English translation of your advice.
|
| 79 |
-
4. [MUSIC]: English prompt: Guitar:{g_inst}, Bass:{b_inst}, Drums:{d_inst}, Chords:{chords}
|
| 80 |
"""
|
| 81 |
|
| 82 |
ai_text_raw = ""
|
|
@@ -96,15 +95,14 @@ async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, cho
|
|
| 96 |
out = qwen(input_t, max_new_tokens=1024)
|
| 97 |
ai_text_raw = out[0]['generated_text'].split("assistant\n")[-1]
|
| 98 |
|
| 99 |
-
# ํ์ฑ ๋ก์ง
|
| 100 |
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 101 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 102 |
trans_match = re.search(r'\[TRANSLATION\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 103 |
|
| 104 |
-
tab_display = tab_match.group(1).strip() if tab_match else "No Detailed
|
| 105 |
eng_translation = trans_match.group(1).strip() if trans_match else ""
|
| 106 |
|
| 107 |
-
#
|
| 108 |
speech_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL | re.IGNORECASE)
|
| 109 |
speech_text = re.sub(r'\[MUSIC:.*?\]', '', speech_text, flags=re.IGNORECASE)
|
| 110 |
speech_text = re.sub(r'\[TRANSLATION\].*?(\[|$)', '', speech_text, flags=re.DOTALL | re.IGNORECASE).strip()
|
|
@@ -113,9 +111,8 @@ async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, cho
|
|
| 113 |
communicate = edge_tts.Communicate(tts_text, m_info["voice"])
|
| 114 |
await communicate.save(voice_path)
|
| 115 |
|
| 116 |
-
# MusicGen ์ฐ์ฃผ ์์ฑ (12์ด)
|
| 117 |
music_gen = ModelManager.get_music()
|
| 118 |
-
music_p = music_match.group(1).strip() if music_match else "rock
|
| 119 |
music_output = music_gen(music_p, forward_params={"max_new_tokens": 512})
|
| 120 |
audio_data = np.squeeze(music_output["audio"])
|
| 121 |
audio_int16 = (audio_data * 32767).astype(np.int16)
|
|
@@ -124,7 +121,7 @@ async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, cho
|
|
| 124 |
return speech_text, voice_path, music_path, tab_display, eng_translation
|
| 125 |
|
| 126 |
except Exception as e:
|
| 127 |
-
return f"Error: {str(e)}", None, None, "No
|
| 128 |
|
| 129 |
with gr.Blocks() as demo:
|
| 130 |
inputs = [gr.Textbox(visible=False) for _ in range(6)]
|
|
|
|
| 32 |
cls._music_pipeline = pipeline("text-to-audio", "facebook/musicgen-small", device="cpu")
|
| 33 |
return cls._music_pipeline
|
| 34 |
|
| 35 |
+
# ํ๋ฅด์๋ ๋ฐ ๋ฉค๋ฒ ๋งต (๊ธฐ์กด ์ ์ง)
|
| 36 |
PERSONA_MAP = {
|
| 37 |
+
"์์ค (Korea)": "์์ ์ ์ด๋ฉด์๋ ๊ฐ๋ ฌํ K-Rock ๋ฆฌ๋. ์ง์งํ๊ณ ๋ฐ๋ปํ๊ฒ ์กฐ์ธํจ.",
|
| 38 |
"Chloe (USA)": "์์ ๋ถ๋ฐฉํ ์บ๋ฆฌํฌ๋์ ํํฌ ๋ฝ์คํ. ๊ฑฐ์นจ์๊ณ ์ฟจํ๋ฉฐ ์๋์ ํฑํ ๋งํฌ.",
|
| 39 |
"Naomi (Japan)": "์๋ฒฝ์ฃผ์ J-Rock ๊ธฐํ๋ฆฌ์คํธ. ์ฌ์ธํ๊ณ ์์ ๋ฐ๋ฅด๋ฉฐ ์์
์ด๋ก ์ ๋ ์นด๋ก์.",
|
| 40 |
"Beatrice (Brazil)": "์ด์ ์ ์ธ ์ผ๋ฐ ๋ฝ์ปค. ๊ธ์ ์ ์ด๊ณ ๋ฆฌ๋ฌ๊ฐ์ด ๋์น๋ฉฐ ์ธ์์ ์ฆ๊ฑฐ์์ ๊ฐ์กฐํจ.",
|
|
|
|
| 44 |
"Sophie (France)": "์์ ์ ์์กด์ฌ์ด ๊ฐํ ์๋ฐฉ๊ฐ๋ฅด๋ ๋ฝ์ปค. ์์ ์ด๊ณ ์ธ๋ จ๋ ํํ์ ์ฆ๊ฒจ ์."
|
| 45 |
}
|
| 46 |
|
|
|
|
| 47 |
LANG_MEMBER_MAP = {
|
| 48 |
"Korean": {"name": "์์ค (Korea)", "voice": "ko-KR-SunHiNeural"},
|
| 49 |
"English": {"name": "Chloe (USA)", "voice": "en-US-AriaNeural"},
|
|
|
|
| 64 |
m_info = LANG_MEMBER_MAP.get(selected_lang, LANG_MEMBER_MAP["Korean"])
|
| 65 |
persona = PERSONA_MAP.get(m_info['name'], "์ด์ ์ ์ธ ๋ฝ์คํ")
|
| 66 |
|
| 67 |
+
# [์ง์ ์์ ] ๋ณธ๋ฌธ์ 5์ค ์ด๋ด ์์ฝ, ๋๋จธ์ง๋ [TAB] ์น์
์ ํตํฉ
|
| 68 |
system_prompt = f"""You are the rock star '{m_info['name']}'. Respond ONLY in {selected_lang}.
|
| 69 |
Persona: {persona}.
|
| 70 |
|
| 71 |
CRITICAL RULES:
|
| 72 |
+
1. MAIN ADVICE: Summarize your advice in exactly 3 to 5 sentences. This will be shown in the main chat.
|
| 73 |
+
2. [TAB] SECTION: This is where you provide all long, detailed explanations.
|
| 74 |
+
- Explain the theory, chord progression, and tips in detail here.
|
| 75 |
+
- Must include Drum patterns (e.g., H|x-x-x-x| S|--o---o-|).
|
| 76 |
+
- Must include Guitar Solo Tab with fret numbers (e.g., e|--12-15-12--|).
|
| 77 |
+
3. [TRANSLATION]: English translation of your 3-5 sentence advice only.
|
| 78 |
+
4. [MUSIC]: English prompt for MusicGen: Guitar:{g_inst}, Bass:{b_inst}, Drums:{d_inst}, Chords:{chords}
|
| 79 |
"""
|
| 80 |
|
| 81 |
ai_text_raw = ""
|
|
|
|
| 95 |
out = qwen(input_t, max_new_tokens=1024)
|
| 96 |
ai_text_raw = out[0]['generated_text'].split("assistant\n")[-1]
|
| 97 |
|
|
|
|
| 98 |
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 99 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 100 |
trans_match = re.search(r'\[TRANSLATION\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 101 |
|
| 102 |
+
tab_display = tab_match.group(1).strip() if tab_match else "No Detailed Data"
|
| 103 |
eng_translation = trans_match.group(1).strip() if trans_match else ""
|
| 104 |
|
| 105 |
+
# TTS ์์ฑ์์ ๋ฒ์ญ๋ฌธ ์ ์ธ ๋ก์ง ๊ฐํ
|
| 106 |
speech_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL | re.IGNORECASE)
|
| 107 |
speech_text = re.sub(r'\[MUSIC:.*?\]', '', speech_text, flags=re.IGNORECASE)
|
| 108 |
speech_text = re.sub(r'\[TRANSLATION\].*?(\[|$)', '', speech_text, flags=re.DOTALL | re.IGNORECASE).strip()
|
|
|
|
| 111 |
communicate = edge_tts.Communicate(tts_text, m_info["voice"])
|
| 112 |
await communicate.save(voice_path)
|
| 113 |
|
|
|
|
| 114 |
music_gen = ModelManager.get_music()
|
| 115 |
+
music_p = music_match.group(1).strip() if music_match else "rock"
|
| 116 |
music_output = music_gen(music_p, forward_params={"max_new_tokens": 512})
|
| 117 |
audio_data = np.squeeze(music_output["audio"])
|
| 118 |
audio_int16 = (audio_data * 32767).astype(np.int16)
|
|
|
|
| 121 |
return speech_text, voice_path, music_path, tab_display, eng_translation
|
| 122 |
|
| 123 |
except Exception as e:
|
| 124 |
+
return f"Error: {str(e)}", None, None, "No Data", "Error"
|
| 125 |
|
| 126 |
with gr.Blocks() as demo:
|
| 127 |
inputs = [gr.Textbox(visible=False) for _ in range(6)]
|