Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,11 +29,11 @@ async def band_consulting(user_input, member_name, lang_code):
|
|
| 29 |
lang_map = {"ko":"Korean","en":"English","ja":"Japanese","pt":"Portuguese","es":"Spanish","ar":"Arabic","zh":"Chinese","fr":"French"}
|
| 30 |
target_lang = lang_map.get(lang_code, "Korean")
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={GENAI_KEY}"
|
| 35 |
|
| 36 |
-
# β
μ°¨λ¨ λ°©μ§: λͺ¨λ μμ μΉ΄ν
κ³ λ¦¬ BLOCK_NONE μ€μ
|
| 37 |
payload = {
|
| 38 |
"contents": [{"parts": [{"text": f"{system_instruction}\nμ§λ¬Έ: {user_input}"}]}],
|
| 39 |
"safetySettings": [
|
|
@@ -41,47 +41,42 @@ async def band_consulting(user_input, member_name, lang_code):
|
|
| 41 |
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
|
| 42 |
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
|
| 43 |
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"}
|
| 44 |
-
]
|
| 45 |
-
"generationConfig": {
|
| 46 |
-
"temperature": 0.7,
|
| 47 |
-
"maxOutputTokens": 1024
|
| 48 |
-
}
|
| 49 |
}
|
| 50 |
|
| 51 |
-
|
| 52 |
-
res_data = response.json()
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
if 'candidates' not in
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
else:
|
| 60 |
-
ai_text_raw =
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
# 5μ€ μμ½
|
| 70 |
-
clean_text = "\n".join(clean_text.split("\n")[:5])
|
| 71 |
|
|
|
|
| 72 |
voice_path = f"/tmp/v_{member_name.split()[0]}.mp3"
|
| 73 |
await edge_tts.Communicate(clean_text, MEMBERS.get(member_name, "ko-KR-SunHiNeural")).save(voice_path)
|
| 74 |
|
| 75 |
-
|
| 76 |
-
if
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
return clean_text, voice_path, music_path, tab_display
|
| 83 |
except Exception as e:
|
| 84 |
-
return f"System
|
| 85 |
|
| 86 |
with gr.Blocks() as demo:
|
| 87 |
i1 = gr.Textbox(); i2 = gr.Textbox(); i3 = gr.Textbox()
|
|
|
|
| 29 |
lang_map = {"ko":"Korean","en":"English","ja":"Japanese","pt":"Portuguese","es":"Spanish","ar":"Arabic","zh":"Chinese","fr":"French"}
|
| 30 |
target_lang = lang_map.get(lang_code, "Korean")
|
| 31 |
|
| 32 |
+
# ν둬ννΈμ 'κ°κ²°νκ²' λλ΅νλΌλ λͺ
λ Ήμ λ λͺ
νν μ λ¬
|
| 33 |
+
system_instruction = f"λΉμ μ {member_name}μ
λλ€. {target_lang}λ‘λ§ λ΅λ³νμΈμ. μμ±μ 5μ€ μ΄λ΄λ‘ λ§€μ° μ§§κ² μμ½νκ³ , μμΈν μ‘°μΈκ³Ό μ
보λ λ°λμ [TAB] μμ λ£μΌμΈμ. μμ
ν둬ννΈλ [MUSIC: μμ΄ν둬ννΈ]λ‘ μμ±νμΈμ."
|
| 34 |
|
| 35 |
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={GENAI_KEY}"
|
| 36 |
|
|
|
|
| 37 |
payload = {
|
| 38 |
"contents": [{"parts": [{"text": f"{system_instruction}\nμ§λ¬Έ: {user_input}"}]}],
|
| 39 |
"safetySettings": [
|
|
|
|
| 41 |
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
|
| 42 |
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
|
| 43 |
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"}
|
| 44 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
+
res = requests.post(url, json=payload).json()
|
|
|
|
| 48 |
|
| 49 |
+
# β
μ°¨λ¨ λ°μ μ μλμΌλ‘ 'μμ ν' μμ
ν둬ννΈμ λ΅λ³μ κ°μ λ‘ μμ±ν΄μ λ겨μ€
|
| 50 |
+
if 'candidates' not in res or not res['candidates']:
|
| 51 |
+
clean_text = "μ΄λ΄ 리λ, μ΄λ² μ μμ λ΄ μμ μ μκ°μ΄ νν°λ§λ μ λλ‘ κ°λ ¬νκ±Έ? λ½μ€νλ΅κ² μ‘°κΈλ§ μνν΄μ λ€μ λ¬Όμ΄λ΄μ€!"
|
| 52 |
+
tab_display = "μμΈ μ‘°μΈμ΄ νν°λ§λμμ΅λλ€. μ§λ¬Έμ μ‘°κΈ λ€λ₯΄κ² ν΄λ³΄μΈμ."
|
| 53 |
+
music_p = "fast heavy metal drum and bass, energetic rock style" # μμ ν κΈ°λ³Έ ν둬ννΈ
|
| 54 |
else:
|
| 55 |
+
ai_text_raw = res['candidates'][0]['content']['parts'][0]['text']
|
| 56 |
+
# λ°μ΄ν° μΆμΆ λ‘μ§ (κΈ°μ‘΄κ³Ό λμΌ)
|
| 57 |
+
tab_match = re.search(r'\[TAB\](.*?)(\[|$)', ai_text_raw, re.DOTALL)
|
| 58 |
+
music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
|
| 59 |
+
tab_display = tab_match.group(1).strip() if tab_match else "No Score Available"
|
| 60 |
+
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL)
|
| 61 |
+
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
|
| 62 |
+
clean_text = "\n".join(clean_text.split("\n")[:5])
|
| 63 |
+
music_p = music_match.group(1).strip().lower() if music_match else "rock guitar riff"
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
# μμ± μμ±
|
| 66 |
voice_path = f"/tmp/v_{member_name.split()[0]}.mp3"
|
| 67 |
await edge_tts.Communicate(clean_text, MEMBERS.get(member_name, "ko-KR-SunHiNeural")).save(voice_path)
|
| 68 |
|
| 69 |
+
# μμ
μμ± (μ°¨λ¨ μν λ¨μ΄ νν°λ§)
|
| 70 |
+
if any(x in music_p for x in ['laugh', 'vocal', 'voice', 'human', 'sing', 'person']):
|
| 71 |
+
music_p = "intense synthesizer rock riff, high energy"
|
| 72 |
+
|
| 73 |
+
music_output = music_synthesiser(music_p, forward_params={"max_new_tokens": 512})
|
| 74 |
+
music_path = f"/tmp/m_{member_name.split()[0]}.wav"
|
| 75 |
+
scipy.io.wavfile.write(music_path, music_output["sampling_rate"], music_output["audio"][0].T)
|
| 76 |
|
| 77 |
return clean_text, voice_path, music_path, tab_display
|
| 78 |
except Exception as e:
|
| 79 |
+
return f"System Overload: {str(e)}", None, None, "Error"
|
| 80 |
|
| 81 |
with gr.Blocks() as demo:
|
| 82 |
i1 = gr.Textbox(); i2 = gr.Textbox(); i3 = gr.Textbox()
|