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