Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,7 @@ async def band_consulting(user_input, member_name, lang_code):
|
|
| 33 |
|
| 34 |
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={GENAI_KEY}"
|
| 35 |
|
| 36 |
-
# โ
์์
|
| 37 |
payload = {
|
| 38 |
"contents": [{"parts": [{"text": f"{system_instruction}\n์ง๋ฌธ: {user_input}"}]}],
|
| 39 |
"safetySettings": [
|
|
@@ -41,18 +41,23 @@ 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 |
}
|
| 46 |
|
| 47 |
response = requests.post(url, json=payload)
|
| 48 |
res_data = response.json()
|
| 49 |
|
| 50 |
-
# candidates
|
| 51 |
if 'candidates' not in res_data or not res_data['candidates']:
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 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)
|
|
@@ -60,6 +65,9 @@ async def band_consulting(user_input, member_name, lang_code):
|
|
| 60 |
|
| 61 |
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL)
|
| 62 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
voice_path = f"/tmp/v_{member_name.split()[0]}.mp3"
|
| 65 |
await edge_tts.Communicate(clean_text, MEMBERS.get(member_name, "ko-KR-SunHiNeural")).save(voice_path)
|
|
@@ -73,7 +81,7 @@ async def band_consulting(user_input, member_name, lang_code):
|
|
| 73 |
|
| 74 |
return clean_text, voice_path, music_path, tab_display
|
| 75 |
except Exception as e:
|
| 76 |
-
return f"
|
| 77 |
|
| 78 |
with gr.Blocks() as demo:
|
| 79 |
i1 = gr.Textbox(); i2 = gr.Textbox(); i3 = gr.Textbox()
|
|
|
|
| 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 |
{"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 |
response = requests.post(url, json=payload)
|
| 52 |
res_data = response.json()
|
| 53 |
|
| 54 |
+
# 'candidates'๊ฐ ์์ ๊ฒฝ์ฐ๋ฅผ ์ํ ์์ธ ์ฒ๋ฆฌ ๊ฐํ
|
| 55 |
if 'candidates' not in res_data or not res_data['candidates']:
|
| 56 |
+
# ํํฐ๋ง๋ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ ๊ธฐ๋ณธ ๋ต๋ณ ์ธํธ
|
| 57 |
+
fallback_text = f"์ด๋ด ๋ฆฌ๋, ์ง๊ธ ๋ด ์๊ฐ์ด ์ ์ ์ฐจ๋จ๋์ด. ๋ค์ ๋ฌผ์ด๋ด์ค๋? [TAB] ๋ค์ ์๋ํด์ฃผ์ธ์. [MUSIC: powerful rock riff]"
|
| 58 |
+
ai_text_raw = fallback_text
|
| 59 |
+
else:
|
| 60 |
+
ai_text_raw = res_data['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)
|
|
|
|
| 65 |
|
| 66 |
clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL)
|
| 67 |
clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
|
| 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)
|
|
|
|
| 81 |
|
| 82 |
return clean_text, voice_path, music_path, tab_display
|
| 83 |
except Exception as e:
|
| 84 |
+
return f"System Reset Needed: {str(e)}", None, None, "Error"
|
| 85 |
|
| 86 |
with gr.Blocks() as demo:
|
| 87 |
i1 = gr.Textbox(); i2 = gr.Textbox(); i3 = gr.Textbox()
|