benjamin5607 commited on
Commit
bc20562
ยท
verified ยท
1 Parent(s): 8419a4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -31,24 +31,29 @@ class ModelManager:
31
  cls._music_pipeline = pipeline("text-to-audio", "facebook/musicgen-small", device="cpu")
32
  return cls._music_pipeline
33
 
34
- # 8์ธ ๋ฉค๋ฒ„ ๋ณด์ด์Šค (์ƒ๋‹ด ์–ธ์–ด์™€ ๊ด€๊ณ„์—†์ด ๋ฉค๋ฒ„ ๊ณ ์œ  ๋ณด์ด์Šค ์œ ์ง€)
35
- MEMBERS_VOICE = {
36
- "์„œ์œค (Korea)": "ko-KR-SunHiNeural", "Chloe (USA)": "en-US-AriaNeural",
37
- "Naomi (Japan)": "ja-JP-NanamiNeural", "Beatrice (Brazil)": "pt-BR-FranciscaNeural",
38
- "Elena (Spain)": "es-ES-ElviraNeural", "Amira (Egypt)": "ar-EG-SalmaNeural",
39
- "Liwei (China)": "zh-CN-XiaoxiaoNeural", "Sophie (France)": "fr-FR-DeniseNeural"
 
 
 
 
40
  }
41
 
42
- async def band_consulting(user_input, member_name, consult_lang, g_inst, b_inst, d_inst, chords):
43
  req_id = str(uuid.uuid4())[:8]
44
  voice_path = f"/tmp/v_{req_id}.mp3"
45
  music_path = f"/tmp/m_{req_id}.wav"
46
 
47
- jam_context = f"Guitar: {g_inst}, Bass: {b_inst}, Drums: {d_inst}, Chords: {chords}"
 
 
48
 
49
- # ๋ฆฌ๋”๋‹˜ ์ง€์‹œ: ์„ ํƒ๋œ consult_lang์œผ๋กœ ๋‹ต๋ณ€ ๊ฐ•์ œ
50
- system_prompt = f"""You are {member_name}, a global rock star.
51
- You MUST respond ONLY in the language: {consult_lang}.
52
  Provide 5-7 lines of professional music advice.
53
  [TAB] Section: Detailed chords/tabs.
54
  [MUSIC] Section: English prompt reflecting: {jam_context}"""
@@ -71,17 +76,17 @@ async def band_consulting(user_input, member_name, consult_lang, g_inst, b_inst,
71
 
72
  tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL | re.IGNORECASE)
73
  music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
74
- tab_display = tab_match.group(1).strip() if tab_match else "No Score Data"
75
  clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL | re.IGNORECASE)
76
  clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text, flags=re.IGNORECASE).strip()
77
 
78
- # TTS ๋ณด์ด์Šค (๋ฉค๋ฒ„ ์ด๋ฆ„์— ๋งž๋Š” ๋ณด์ด์Šค ์„ ํƒ)
79
- voice_name = MEMBERS_VOICE.get(member_name, "en-US-AriaNeural")
80
- communicate = edge_tts.Communicate(re.sub(r'[\*\#\-\_\~\|]', '', clean_text), voice_name)
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 guitar riff"
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,7 +95,8 @@ async def band_consulting(user_input, member_name, consult_lang, g_inst, b_inst,
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(7)]
 
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)
96
  btn.click(band_consulting, inputs, outputs, api_name="predict")
 
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"},
38
+ "Japanese": {"name": "Naomi (Japan)", "voice": "ja-JP-NanamiNeural"},
39
+ "Portuguese": {"name": "Beatrice (Brazil)", "voice": "pt-BR-FranciscaNeural"},
40
+ "Spanish": {"name": "Elena (Spain)", "voice": "es-ES-ElviraNeural"},
41
+ "Arabic": {"name": "Amira (Egypt)", "voice": "ar-EG-SalmaNeural"},
42
+ "Chinese": {"name": "Liwei (China)", "voice": "zh-CN-XiaoxiaoNeural"},
43
+ "French": {"name": "Sophie (France)", "voice": "fr-FR-DeniseNeural"}
44
  }
45
 
46
+ async def band_consulting(user_input, selected_lang, g_inst, b_inst, d_inst, chords):
47
  req_id = str(uuid.uuid4())[:8]
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}"""
 
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
  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)
102
  btn.click(band_consulting, inputs, outputs, api_name="predict")