Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,49 +45,26 @@ LANG_MEMBER_MAP = {
|
|
| 45 |
}
|
| 46 |
|
| 47 |
async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, chords):
|
| 48 |
-
|
| 49 |
-
voice_path = f"/tmp/v_{req_id}.mp3"
|
| 50 |
-
music_path = f"/tmp/m_{req_id}.wav"
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
# [TRANSLATION] ์น์
์ ์ถ๊ฐํ๋๋ก ํ๋กฌํํธ ์์
|
| 55 |
-
system_prompt = f"""You are {m_info['name']}. Respond ONLY in {selected_lang}.
|
| 56 |
-
Provide 5-7 sentences of music advice.
|
| 57 |
-
At the end, add [TRANSLATION] followed by the English translation of your advice.
|
| 58 |
-
[TAB] Section: Detailed chords/tabs.
|
| 59 |
-
[MUSIC] Section: English prompt for MusicGen: Guitar:{g_inst}, Bass:{b_inst}, Drums:{d_inst}, Chords:{chords}"""
|
| 60 |
-
|
| 61 |
-
ai_text_raw = ""
|
| 62 |
-
groq_client = ModelManager.get_groq()
|
| 63 |
-
if groq_client:
|
| 64 |
-
try:
|
| 65 |
-
res = groq_client.chat.completions.create(
|
| 66 |
-
messages=[{"role": "system", "content": system_prompt}, {"role": "user", "content": user_input}],
|
| 67 |
-
model="llama-3.3-70b-versatile"
|
| 68 |
-
)
|
| 69 |
-
ai_text_raw = res.choices[0].message.content
|
| 70 |
-
except: pass
|
| 71 |
-
|
| 72 |
-
if not ai_text_raw:
|
| 73 |
-
qwen = ModelManager.get_qwen()
|
| 74 |
-
out = qwen(f"<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{user_input}<|im_end|>\nassistant\n", max_new_tokens=1024)
|
| 75 |
-
ai_text_raw = out[0]['generated_text'].split("assistant\n")[-1]
|
| 76 |
-
|
| 77 |
-
# ๋ฐ์ดํฐ ํ์ฑ (๋ณธ๋ฌธ, ๋ฒ์ญ, ์
๋ณด, ์์
)
|
| 78 |
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 79 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 80 |
trans_match = re.search(r'\[TRANSLATION\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 81 |
|
| 82 |
-
tab_display = tab_match.group(1).strip() if tab_match else "No Data"
|
| 83 |
translation = trans_match.group(1).strip() if trans_match else ""
|
| 84 |
|
|
|
|
| 85 |
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL | re.IGNORECASE)
|
| 86 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text, flags=re.IGNORECASE)
|
| 87 |
clean_text = re.sub(r'\[TRANSLATION\].*?(\[|$)', '', clean_text, flags=re.DOTALL | re.IGNORECASE).strip()
|
| 88 |
|
| 89 |
-
# TTS ์์ฑ (๋ค์ดํฐ๋ธ
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
await communicate.save(voice_path)
|
| 92 |
|
| 93 |
# MusicGen (12์ด)
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, chords):
|
| 48 |
+
# ... (์๋ต: LLM ๋ต๋ณ ์์ฑ ๋ก์ง ๋์ผ)
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
# 1. ํ์ฑ ๋ก์ง ์ ๊ตํ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 52 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 53 |
trans_match = re.search(r'\[TRANSLATION\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
|
| 54 |
|
| 55 |
+
tab_display = tab_match.group(1).strip() if tab_match else "No Tab Data"
|
| 56 |
translation = trans_match.group(1).strip() if trans_match else ""
|
| 57 |
|
| 58 |
+
# โ
ํต์ฌ: ๋งด๋ฒ๊ฐ ์ฝ์ ํ
์คํธ(TTS)๋ ๋ฒ์ญ๋ฌธ์ ์ ์ธํ clean_text๋ง ์ฌ์ฉ
|
| 59 |
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL | re.IGNORECASE)
|
| 60 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text, flags=re.IGNORECASE)
|
| 61 |
clean_text = re.sub(r'\[TRANSLATION\].*?(\[|$)', '', clean_text, flags=re.DOTALL | re.IGNORECASE).strip()
|
| 62 |
|
| 63 |
+
# TTS ์์ฑ (๋ฒ์ญ๋ฌธ ์์ด ๋ค์ดํฐ๋ธ ์ค๋ช
๋ง ์ฝ์)
|
| 64 |
+
m_info = LANG_MEMBER_MAP.get(selected_lang, LANG_MEMBER_MAP["Korean"])
|
| 65 |
+
# ํน์๋ฌธ์ ์ ๊ฑฐ ํ ์์ ํ
์คํธ๋ง ์ ๋ฌ
|
| 66 |
+
tts_text = re.sub(r'[\*\#\-\_\~\|]', '', clean_text)
|
| 67 |
+
communicate = edge_tts.Communicate(tts_text, m_info["voice"])
|
| 68 |
await communicate.save(voice_path)
|
| 69 |
|
| 70 |
# MusicGen (12์ด)
|