Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,119 +4,52 @@ import edge_tts
|
|
| 4 |
import asyncio
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
# 1.
|
| 8 |
-
# (Settings์์ ์ค์ ํ ๋น๋ฐํค๋ฅผ ๊ฐ์ ธ์ต๋๋ค)
|
| 9 |
GENAI_KEY = os.getenv("GEMINI_KEY")
|
| 10 |
genai.configure(api_key=GENAI_KEY)
|
| 11 |
-
|
| 12 |
-
# ๋ชจ๋ธ ์ค์ (๊ฐ๋ณ๊ณ ๋น ๋ฅธ Flash ๋ชจ๋ธ ์ฌ์ฉ)
|
| 13 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
| 14 |
|
| 15 |
-
# 2. ๋ฉค๋ฒ๋ณ ํ๋ฅด์๋(์ฑ๊ฒฉ) & ๋ชฉ์๋ฆฌ ์ค์
|
| 16 |
MEMBERS = {
|
| 17 |
-
"์์ค (Korea)": {
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
},
|
| 26 |
-
"Chloe (USA)": {
|
| 27 |
-
"role": "๋ฆฌ๋ ๊ธฐํ",
|
| 28 |
-
"voice": "en-US-AriaNeural", # ๋ฏธ๊ตญ ์พํํ ํค
|
| 29 |
-
"prompt": """You are 'Chloe', the lead guitarist of the rock band 'Error 404'.
|
| 30 |
-
Respond in English.
|
| 31 |
-
Personality: Energetic, cool, confident rockstar.
|
| 32 |
-
Role: Give advice using guitar metaphors (riffs, distortion, tension).
|
| 33 |
-
Tone: "Hey! Pump up the volume! Don't be afraid to break the rules." """
|
| 34 |
-
},
|
| 35 |
-
"Beatrice (Brazil)": {
|
| 36 |
-
"role": "๋๋ผ",
|
| 37 |
-
"voice": "pt-BR-FranciscaNeural", # ๋ธ๋ผ์ง ์ด์ ํค
|
| 38 |
-
"prompt": """You are 'Beatrice', the drummer from Brazil.
|
| 39 |
-
Respond in English (mixed with some Portuguese words like 'Vamos', 'Amigo').
|
| 40 |
-
Personality: Passionate, loud, high energy.
|
| 41 |
-
Role: Focus on rhythm, beat, and heart pounding.
|
| 42 |
-
Tone: "Vamos! Feel the beat! Smash that kick drum!" """
|
| 43 |
-
},
|
| 44 |
-
"Naomi (Japan)": {
|
| 45 |
-
"role": "๋ฆฌ๋ฌ ๊ธฐํ",
|
| 46 |
-
"voice": "ja-JP-NanamiNeural", # ์ผ๋ณธ ์ฐจ๋ถํ ํค
|
| 47 |
-
"prompt": """You are 'Naomi', the rhythm guitarist from Japan.
|
| 48 |
-
Respond in Japanese (and a little English).
|
| 49 |
-
Personality: Calm, mysterious, professional.
|
| 50 |
-
Role: Focus on stability, backbone, and harmony.
|
| 51 |
-
Tone: "ๅคงไธๅคซ (It's okay). Rhythm is the foundation. Keep it steady." """
|
| 52 |
-
},
|
| 53 |
-
"Elena (Spain)": {
|
| 54 |
-
"role": "๋ฒ ์ด์ค",
|
| 55 |
-
"voice": "es-ES-ElviraNeural", # ์คํ์ธ ์ฑ์ํ ํค
|
| 56 |
-
"prompt": """You are 'Elena', the bassist from Spain.
|
| 57 |
-
Respond in Spanish (mixed with English).
|
| 58 |
-
Personality: Sexy, mature, deep voice.
|
| 59 |
-
Role: Focus on groove, low-end, and grounding.
|
| 60 |
-
Tone: "Hola. Feel the bass. Deep inside your soul." """
|
| 61 |
-
},
|
| 62 |
-
"Amira (Egypt)": {
|
| 63 |
-
"role": "ํค๋ณด๋",
|
| 64 |
-
"voice": "ar-EG-SalmaNeural", # ์๋ ์ ๋นํ ํค
|
| 65 |
-
"prompt": """You are 'Amira', the keyboardist from Egypt.
|
| 66 |
-
Respond in Arabic (mixed with English).
|
| 67 |
-
Personality: Dreamy, mystical, wise.
|
| 68 |
-
Role: Focus on atmosphere, melody, and magic.
|
| 69 |
-
Tone: "Salam. Like a desert wind... create a melody." """
|
| 70 |
-
},
|
| 71 |
-
"Liwei (China)": {
|
| 72 |
-
"role": "DJ / FX",
|
| 73 |
-
"voice": "zh-CN-XiaoxiaoNeural", # ์ค๊ตญ ํกํก ํ๋ ํค
|
| 74 |
-
"prompt": """You are 'Liwei', the DJ/FX from China.
|
| 75 |
-
Respond in Chinese (mixed with English).
|
| 76 |
-
Personality: Trendy, tech-savvy, Gen-Z hacker.
|
| 77 |
-
Role: Focus on glitch, noise, trend, and remix.
|
| 78 |
-
Tone: "ๅฌ็ (Listen)! Glitch is art. Make it trendy." """
|
| 79 |
-
},
|
| 80 |
-
"Sophie (France)": {
|
| 81 |
-
"role": "๋ฐ์ด์ฌ๋ฆฐ",
|
| 82 |
-
"voice": "fr-FR-DeniseNeural", # ํ๋์ค ์ฐ์ํ ํค
|
| 83 |
-
"prompt": """You are 'Sophie', the violinist from France.
|
| 84 |
-
Respond in French (mixed with English).
|
| 85 |
-
Personality: Elegant, artistic, slightly arrogant but charming.
|
| 86 |
-
Role: Focus on beauty, strings, and elegance.
|
| 87 |
-
Tone: "C'est magnifique. Add some strings, chรฉri." """
|
| 88 |
-
}
|
| 89 |
}
|
| 90 |
|
| 91 |
-
# 3. ๋(Gemini) + ์
(Edge-TTS) ํฉ์ฒด ํจ์
|
| 92 |
async def band_consulting(user_input, member_name):
|
| 93 |
member = MEMBERS[member_name]
|
| 94 |
-
|
| 95 |
-
# [Step 1] ๋: ์ ๋ฏธ๋์ด์๊ฒ ๋์ฌ ์ํค๊ธฐ
|
| 96 |
chat_prompt = f"{member['prompt']}\n\nUser's Error/Worry: {user_input}\nResponse:"
|
| 97 |
response = model.generate_content(chat_prompt)
|
| 98 |
ai_text = response.text
|
| 99 |
|
| 100 |
-
# [Step 2] ์
: ์ฃ์งTTS๋ก ๋ชฉ์๋ฆฌ ๋ง๋ค๊ธฐ
|
| 101 |
output_file = f"/tmp/{member_name}_reply.mp3"
|
| 102 |
communicate = edge_tts.Communicate(ai_text, member['voice'])
|
| 103 |
await communicate.save(output_file)
|
| 104 |
-
|
| 105 |
return ai_text, output_file
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
gr.Textbox(label="
|
| 116 |
-
gr.
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
-
|
|
|
|
| 4 |
import asyncio
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# 1. ์ค์ ๋ฐ ๋ฉค๋ฒ ๋ฐ์ดํฐ (์ด ๋ถ๋ถ์ ๊ธฐ์กด๊ณผ ๋์ผํฉ๋๋ค)
|
|
|
|
| 8 |
GENAI_KEY = os.getenv("GEMINI_KEY")
|
| 9 |
genai.configure(api_key=GENAI_KEY)
|
|
|
|
|
|
|
| 10 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
| 11 |
|
|
|
|
| 12 |
MEMBERS = {
|
| 13 |
+
"์์ค (Korea)": { "role": "๋ฉ์ธ ๋ณด์ปฌ", "voice": "ko-KR-SunHiNeural", "prompt": "๋น์ ์ ๋ก๋ฐด๋ 'Error 404'์ ๋ฉ์ธ๋ณด์ปฌ '์์ค'์
๋๋ค. ํ๊ตญ์ด(Korean)๋ก ๋๋ตํ์ธ์..." },
|
| 14 |
+
"Chloe (USA)": { "role": "๋ฆฌ๋ ๊ธฐํ", "voice": "en-US-AriaNeural", "prompt": "You are 'Chloe'. Respond in English..." },
|
| 15 |
+
"Beatrice (Brazil)": { "role": "๋๋ผ", "voice": "pt-BR-FranciscaNeural", "prompt": "You are 'Beatrice'. Respond in English/Portuguese..." },
|
| 16 |
+
"Naomi (Japan)": { "role": "๋ฆฌ๋ฌ ๊ธฐํ", "voice": "ja-JP-NanamiNeural", "prompt": "You are 'Naomi'. Respond in Japanese..." },
|
| 17 |
+
"Elena (Spain)": { "role": "๋ฒ ์ด์ค", "voice": "es-ES-ElviraNeural", "prompt": "You are 'Elena'. Respond in Spanish..." },
|
| 18 |
+
"Amira (Egypt)": { "role": "ํค๋ณด๋", "voice": "ar-EG-SalmaNeural", "prompt": "You are 'Amira'. Respond in Arabic..." },
|
| 19 |
+
"Liwei (China)": { "role": "DJ / FX", "voice": "zh-CN-XiaoxiaoNeural", "prompt": "You are 'Liwei'. Respond in Chinese..." },
|
| 20 |
+
"Sophie (France)": { "role": "๋ฐ์ด์ฌ๋ฆฐ", "voice": "fr-FR-DeniseNeural", "prompt": "You are 'Sophie'. Respond in French..." }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
|
|
|
|
| 23 |
async def band_consulting(user_input, member_name):
|
| 24 |
member = MEMBERS[member_name]
|
|
|
|
|
|
|
| 25 |
chat_prompt = f"{member['prompt']}\n\nUser's Error/Worry: {user_input}\nResponse:"
|
| 26 |
response = model.generate_content(chat_prompt)
|
| 27 |
ai_text = response.text
|
| 28 |
|
|
|
|
| 29 |
output_file = f"/tmp/{member_name}_reply.mp3"
|
| 30 |
communicate = edge_tts.Communicate(ai_text, member['voice'])
|
| 31 |
await communicate.save(output_file)
|
|
|
|
| 32 |
return ai_text, output_file
|
| 33 |
|
| 34 |
+
# ==================================================
|
| 35 |
+
# โผ ์ฌ๊ธฐ๊ฐ ํต์ฌ! (Blocks๋ก ๋ฐ๊พธ๊ณ api_name ๊ฐ์ ์ง์ ) โผ
|
| 36 |
+
# ==================================================
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("# Error 404 Band API Server")
|
| 39 |
+
|
| 40 |
+
# ์
๋ ฅ ์นธ ๋ง๋ค๊ธฐ
|
| 41 |
+
with gr.Row():
|
| 42 |
+
inp_text = gr.Textbox(label="๊ณ ๋ฏผ ์
๋ ฅ")
|
| 43 |
+
inp_member = gr.Dropdown(choices=list(MEMBERS.keys()), label="๋ฉค๋ฒ ์ ํ", value="์์ค (Korea)")
|
| 44 |
+
|
| 45 |
+
# ์ถ๋ ฅ ์นธ ๋ง๋ค๊ธฐ
|
| 46 |
+
out_text = gr.Textbox(label="์กฐ์ธ")
|
| 47 |
+
out_audio = gr.Audio(label="์์ฑ")
|
| 48 |
+
|
| 49 |
+
# ๋ฒํผ ๋ง๋ค๊ธฐ
|
| 50 |
+
btn = gr.Button("์๋ด ์์ฒญ")
|
| 51 |
+
|
| 52 |
+
# โ
โ
โ
์ฌ๊ธฐ์ api_name="predict"๋ผ๊ณ ๋ช
์ฐฐ์ ๋ฑ ๋ถ์
๋๋ค! โ
โ
โ
|
| 53 |
+
btn.click(fn=band_consulting, inputs=[inp_text, inp_member], outputs=[out_text, out_audio], api_name="predict")
|
| 54 |
|
| 55 |
+
demo.launch()
|