Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,20 +78,25 @@ async def band_consulting(user_input, member_name, consult_category):
|
|
| 78 |
try:
|
| 79 |
member = MEMBERS.get(member_name, MEMBERS["μμ€ (Korea)"])
|
| 80 |
|
| 81 |
-
# β
μΈμ΄ κ²°μ λ‘μ§
|
| 82 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
system_instruction = f"""
|
| 86 |
{member['prompt']}
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
μ‘°μΈμ μ 곡ν λ€ λ°λμ λ§μ§λ§μ λ€μ νμμ ν¬ν¨νμΈμ:
|
| 90 |
1. [TAB]: μμ
μ κ°λ¨ν μ½λ μ§νμ΄λ ν
μ€νΈ μ
보λ₯Ό 그리μΈμ.
|
| 91 |
2. [MUSIC]: λΆμΌμ μ΄μΈλ¦¬λ κ³ μμ§ μμ
ν둬ννΈλ₯Ό μμ΄λ‘ μμ±νμΈμ.
|
| 92 |
"""
|
| 93 |
|
| 94 |
-
# Gemini API νΈμΆ
|
| 95 |
url = f"https://generativelanguage.googleapis.com/v1beta/models/{ACTIVE_MODEL}:generateContent?key={GENAI_KEY}"
|
| 96 |
payload = {"contents": [{"parts": [{"text": f"{system_instruction}\nμ§λ¬Έ: {user_input}"}]}]}
|
| 97 |
res = requests.post(url, json=payload, headers={'Content-Type': 'application/json'})
|
|
@@ -101,26 +106,20 @@ async def band_consulting(user_input, member_name, consult_category):
|
|
| 101 |
|
| 102 |
ai_text_raw = res.json()['candidates'][0]['content']['parts'][0]['text']
|
| 103 |
|
| 104 |
-
# μ
보([TAB]) λ° μμ
λͺ
λ Ή([MUSIC]) μΆμΆ
|
| 105 |
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL)
|
| 106 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 107 |
-
|
| 108 |
tab_display = tab_match.group(1).strip() if tab_match else "No Score Available"
|
| 109 |
|
| 110 |
-
# ν
μ€νΈ μ μ λ° μμ± νν°λ§ (νΉμλ¬Έμ μ κ±°νμ¬ μμ€μ΄κ° μ½μ§ μκ² ν¨)
|
| 111 |
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL)
|
| 112 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
|
| 113 |
tts_text = re.sub(r'[\*\#\-\_\~]', '', clean_text)
|
| 114 |
|
| 115 |
-
# 6. λͺ©μ리(TTS) μμ±
|
| 116 |
voice_path = f"/tmp/v_{member_name.replace(' ', '_')}.mp3"
|
| 117 |
await edge_tts.Communicate(tts_text, member['voice']).save(voice_path)
|
| 118 |
|
| 119 |
-
# 7. μμ
(MusicGen) μμ± (μμ§ λ³΄μ νΈλ¦)
|
| 120 |
music_path = None
|
| 121 |
if music_match and music_synthesiser:
|
| 122 |
music_p = music_match.group(1).strip() + ", high quality, studio recording, power rock, intense drums"
|
| 123 |
-
# guidance_scale=4.5λ‘ λμ¬ μμ§ λ° ν둬ννΈ μ νλ ν₯μ
|
| 124 |
music_output = music_synthesiser(music_p, forward_params={"max_new_tokens": 512, "guidance_scale": 4.5, "do_sample": True})
|
| 125 |
music_path = f"/tmp/m_{member_name.replace(' ', '_')}.wav"
|
| 126 |
scipy.io.wavfile.write(music_path, music_output["sampling_rate"], music_output["audio"][0].T)
|
|
@@ -128,7 +127,7 @@ async def band_consulting(user_input, member_name, consult_category):
|
|
| 128 |
return clean_text, voice_path, music_path, tab_display
|
| 129 |
|
| 130 |
except Exception as e:
|
| 131 |
-
print(f"β Error
|
| 132 |
return f"λ°΄λ μμ€ν
μ€λ₯: {str(e)}", None, None, "Error"
|
| 133 |
|
| 134 |
# 8. Gradio μΈν°νμ΄μ€ μ μ (APIμ©)
|
|
|
|
| 78 |
try:
|
| 79 |
member = MEMBERS.get(member_name, MEMBERS["μμ€ (Korea)"])
|
| 80 |
|
| 81 |
+
# β
μΈμ΄ κ²°μ λ‘μ§ λ³΄κ°: μΉ΄ν
κ³ λ¦¬ ν
μ€νΈμμ μΈμ΄ μ 보λ₯Ό νμ€ν μΆμΆ
|
| 82 |
+
# μ: "πΊπΈ English (Global Random π²) / Guitar" -> "English"
|
| 83 |
+
requested_lang = "English" if "English" in consult_category else "Korean"
|
| 84 |
|
| 85 |
system_instruction = f"""
|
| 86 |
{member['prompt']}
|
| 87 |
+
|
| 88 |
+
[CRITICAL RULE]
|
| 89 |
+
The user wants to consult in {requested_lang}.
|
| 90 |
+
Regardless of your origin, you MUST respond ENTIRELY in {requested_lang}.
|
| 91 |
+
Do not use your native language if it's different from {requested_lang}.
|
| 92 |
+
|
| 93 |
+
[Current Category: {consult_category}]
|
| 94 |
|
| 95 |
μ‘°μΈμ μ 곡ν λ€ λ°λμ λ§μ§λ§μ λ€μ νμμ ν¬ν¨νμΈμ:
|
| 96 |
1. [TAB]: μμ
μ κ°λ¨ν μ½λ μ§νμ΄λ ν
μ€νΈ μ
보λ₯Ό 그리μΈμ.
|
| 97 |
2. [MUSIC]: λΆμΌμ μ΄μΈλ¦¬λ κ³ μμ§ μμ
ν둬ννΈλ₯Ό μμ΄λ‘ μμ±νμΈμ.
|
| 98 |
"""
|
| 99 |
|
|
|
|
| 100 |
url = f"https://generativelanguage.googleapis.com/v1beta/models/{ACTIVE_MODEL}:generateContent?key={GENAI_KEY}"
|
| 101 |
payload = {"contents": [{"parts": [{"text": f"{system_instruction}\nμ§λ¬Έ: {user_input}"}]}]}
|
| 102 |
res = requests.post(url, json=payload, headers={'Content-Type': 'application/json'})
|
|
|
|
| 106 |
|
| 107 |
ai_text_raw = res.json()['candidates'][0]['content']['parts'][0]['text']
|
| 108 |
|
|
|
|
| 109 |
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL)
|
| 110 |
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
|
|
|
| 111 |
tab_display = tab_match.group(1).strip() if tab_match else "No Score Available"
|
| 112 |
|
|
|
|
| 113 |
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL)
|
| 114 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
|
| 115 |
tts_text = re.sub(r'[\*\#\-\_\~]', '', clean_text)
|
| 116 |
|
|
|
|
| 117 |
voice_path = f"/tmp/v_{member_name.replace(' ', '_')}.mp3"
|
| 118 |
await edge_tts.Communicate(tts_text, member['voice']).save(voice_path)
|
| 119 |
|
|
|
|
| 120 |
music_path = None
|
| 121 |
if music_match and music_synthesiser:
|
| 122 |
music_p = music_match.group(1).strip() + ", high quality, studio recording, power rock, intense drums"
|
|
|
|
| 123 |
music_output = music_synthesiser(music_p, forward_params={"max_new_tokens": 512, "guidance_scale": 4.5, "do_sample": True})
|
| 124 |
music_path = f"/tmp/m_{member_name.replace(' ', '_')}.wav"
|
| 125 |
scipy.io.wavfile.write(music_path, music_output["sampling_rate"], music_output["audio"][0].T)
|
|
|
|
| 127 |
return clean_text, voice_path, music_path, tab_display
|
| 128 |
|
| 129 |
except Exception as e:
|
| 130 |
+
print(f"β Error: {e}")
|
| 131 |
return f"λ°΄λ μμ€ν
μ€λ₯: {str(e)}", None, None, "Error"
|
| 132 |
|
| 133 |
# 8. Gradio μΈν°νμ΄μ€ μ μ (APIμ©)
|