Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,21 +40,18 @@ MEMBERS = {
|
|
| 40 |
"Chloe (USA)": { "voice": "en-US-AriaNeural", "prompt": "You are 'Chloe', the guitarist. Speak in English. Focus on guitar tabs and tones." },
|
| 41 |
"Beatrice (Brazil)": { "voice": "pt-BR-FranciscaNeural", "prompt": "You are 'Beatrice', the drummer. Focus on rhythm patterns and groovy beats." }
|
| 42 |
}
|
| 43 |
-
|
| 44 |
async def band_consulting(user_input, member_name, consult_category):
|
| 45 |
try:
|
|
|
|
| 46 |
member = MEMBERS.get(member_name, MEMBERS["μμ€ (Korea)"])
|
| 47 |
|
| 48 |
-
# μμ€ν
ν둬ννΈ: μ
보μ μμ
μμ±μ ꡬ체ν
|
| 49 |
system_instruction = f"""
|
| 50 |
{member['prompt']}
|
| 51 |
[μλ΄ λΆμΌ: {consult_category}]
|
| 52 |
-
|
| 53 |
λΉμ μ μ λ¬Έκ°λ‘μ μ‘°μΈμ νκ³ , λ§μ§λ§μ λ κ°μ§λ₯Ό λ°λμ ν¬ν¨νμΈμ:
|
| 54 |
-
1. [TAB]: μμ
μ κ°λ¨ν μ
보λ μ½λ μ§νμ ν
μ€νΈ νμμΌλ‘ 그리μΈμ.
|
| 55 |
-
|
| 56 |
-
2. [MUSIC]: λΆμΌμ νΉνλ κ³ μμ§ μμ
ν둬ννΈλ₯Ό μ μΌμΈμ.
|
| 57 |
-
(High-quality, studio recording, master audio νμ ν¬ν¨)
|
| 58 |
"""
|
| 59 |
|
| 60 |
url = f"https://generativelanguage.googleapis.com/v1beta/models/{ACTIVE_MODEL}:generateContent?key={GENAI_KEY}"
|
|
@@ -62,28 +59,29 @@ async def band_consulting(user_input, member_name, consult_category):
|
|
| 62 |
res = requests.post(url, json=payload)
|
| 63 |
ai_text_raw = res.json()['candidates'][0]['content']['parts'][0]['text']
|
| 64 |
|
| 65 |
-
# μ
보([TAB])μ μμ
([MUSIC]) μΆμΆ
|
| 66 |
tab_match = re.search(r'\[TAB\](.*?)\[', ai_text_raw + '[', re.DOTALL)
|
| 67 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 68 |
|
| 69 |
-
tab_display = tab_match.group(1).strip() if tab_match else "No Score
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
# 1. λͺ©μ리 μμ±
|
| 74 |
voice_path = f"/tmp/v_{member_name}.mp3"
|
| 75 |
-
await edge_tts.Communicate(
|
| 76 |
|
| 77 |
-
# 2. μμ
μμ±
|
| 78 |
music_path = None
|
| 79 |
if music_match and music_synthesiser:
|
| 80 |
-
p = music_match.group(1).strip() + ", high quality, studio recording
|
| 81 |
-
|
| 82 |
-
music = music_synthesiser(p, forward_params={"max_new_tokens": 448, "guidance_scale": 4.5, "do_sample": True})
|
| 83 |
music_path = f"/tmp/m_{member_name}.wav"
|
| 84 |
scipy.io.wavfile.write(music_path, music["sampling_rate"], music["audio"][0].T)
|
| 85 |
|
| 86 |
-
return
|
| 87 |
|
| 88 |
except Exception as e:
|
| 89 |
return f"Error: {e}", None, None, ""
|
|
|
|
| 40 |
"Chloe (USA)": { "voice": "en-US-AriaNeural", "prompt": "You are 'Chloe', the guitarist. Speak in English. Focus on guitar tabs and tones." },
|
| 41 |
"Beatrice (Brazil)": { "voice": "pt-BR-FranciscaNeural", "prompt": "You are 'Beatrice', the drummer. Focus on rhythm patterns and groovy beats." }
|
| 42 |
}
|
| 43 |
+
# app.pyμ band_consulting ν¨μ λΆλΆλ§ μ΄ λ΄μ©μΌλ‘ κ΅μ²΄νμΈμ
|
| 44 |
async def band_consulting(user_input, member_name, consult_category):
|
| 45 |
try:
|
| 46 |
+
# λ©€λ² μ΄λ¦ μ€ν μμ
|
| 47 |
member = MEMBERS.get(member_name, MEMBERS["μμ€ (Korea)"])
|
| 48 |
|
|
|
|
| 49 |
system_instruction = f"""
|
| 50 |
{member['prompt']}
|
| 51 |
[μλ΄ λΆμΌ: {consult_category}]
|
|
|
|
| 52 |
λΉμ μ μ λ¬Έκ°λ‘μ μ‘°μΈμ νκ³ , λ§μ§λ§μ λ κ°μ§λ₯Ό λ°λμ ν¬ν¨νμΈμ:
|
| 53 |
+
1. [TAB]: μμ
μ κ°λ¨ν μ
보λ μ½λ μ§νμ ν
μ€νΈ νμμΌλ‘ 그리μΈμ.
|
| 54 |
+
2. [MUSIC]: λΆμΌμ νΉνλ κ³ μμ§ μμ
ν둬ννΈλ₯Ό μ μΌμΈμ.
|
|
|
|
|
|
|
| 55 |
"""
|
| 56 |
|
| 57 |
url = f"https://generativelanguage.googleapis.com/v1beta/models/{ACTIVE_MODEL}:generateContent?key={GENAI_KEY}"
|
|
|
|
| 59 |
res = requests.post(url, json=payload)
|
| 60 |
ai_text_raw = res.json()['candidates'][0]['content']['parts'][0]['text']
|
| 61 |
|
|
|
|
| 62 |
tab_match = re.search(r'\[TAB\](.*?)\[', ai_text_raw + '[', re.DOTALL)
|
| 63 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 64 |
|
| 65 |
+
tab_display = tab_match.group(1).strip() if tab_match else "No Score"
|
| 66 |
+
|
| 67 |
+
# νΉμλ¬Έμ μ½κΈ° λ°©μ§ νν° (TTSμ© ν
μ€νΈμμ νΉμλ¬Έμ μ κ±°)
|
| 68 |
+
raw_clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL)
|
| 69 |
+
raw_clean_text = re.sub(r'\[MUSIC:.*?\]', '', raw_clean_text).strip()
|
| 70 |
+
tts_text = re.sub(r'[\*\#\-\_\~]', '', raw_clean_text) # μμ€μ΄κ° μ½μ λ λ³ν λ±μ 무μν¨
|
| 71 |
|
| 72 |
+
# 1. λͺ©μ리 μμ± (νν°λ§λ tts_text μ¬μ©)
|
| 73 |
voice_path = f"/tmp/v_{member_name}.mp3"
|
| 74 |
+
await edge_tts.Communicate(tts_text, member['voice']).save(voice_path)
|
| 75 |
|
| 76 |
+
# 2. μμ
μμ±
|
| 77 |
music_path = None
|
| 78 |
if music_match and music_synthesiser:
|
| 79 |
+
p = music_match.group(1).strip() + ", high quality, studio recording"
|
| 80 |
+
music = music_synthesiser(p, forward_params={"max_new_tokens": 448, "guidance_scale": 4.5})
|
|
|
|
| 81 |
music_path = f"/tmp/m_{member_name}.wav"
|
| 82 |
scipy.io.wavfile.write(music_path, music["sampling_rate"], music["audio"][0].T)
|
| 83 |
|
| 84 |
+
return raw_clean_text, voice_path, music_path, tab_display
|
| 85 |
|
| 86 |
except Exception as e:
|
| 87 |
return f"Error: {e}", None, None, ""
|