benjamin5607 commited on
Commit
1c44d4e
ยท
verified ยท
1 Parent(s): ebcf9f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -32
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
- req_id = str(uuid.uuid4())[:8]
49
- voice_path = f"/tmp/v_{req_id}.mp3"
50
- music_path = f"/tmp/m_{req_id}.wav"
51
 
52
- m_info = LANG_MEMBER_MAP.get(selected_lang, LANG_MEMBER_MAP["Korean"])
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
- communicate = edge_tts.Communicate(re.sub(r'[\*\#\-\_\~\|]', '', clean_text), m_info["voice"])
 
 
 
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์ดˆ)