benjamin5607 commited on
Commit
87c6570
ยท
verified ยท
1 Parent(s): bc20562

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
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
- # 8๊ฐœ ์–ธ์–ด๋ณ„ ์ „๋‹ด ๋ฉค๋ฒ„ ๋ฐ ๋ณด์ด์Šค ์„ค์ •
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
- 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}"""
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 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,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)