benjamin5607 commited on
Commit
fb6ce6a
Β·
verified Β·
1 Parent(s): 00cb830

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -40,21 +40,18 @@ MEMBERS = {
40
  "Chloe (USA)": { "voice": "en-US-AriaNeural", "prompt": "You are 'Chloe', the guitarist. Speak in English. Focus on guitar tabs and tones." },
41
  "Beatrice (Brazil)": { "voice": "pt-BR-FranciscaNeural", "prompt": "You are 'Beatrice', the drummer. Focus on rhythm patterns and groovy beats." }
42
  }
43
-
44
  async def band_consulting(user_input, member_name, consult_category):
45
  try:
 
46
  member = MEMBERS.get(member_name, MEMBERS["μ„œμœ€ (Korea)"])
47
 
48
- # μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ: 악보와 μŒμ•… 생성을 ꡬ체화
49
  system_instruction = f"""
50
  {member['prompt']}
51
  [상담 λΆ„μ•Ό: {consult_category}]
52
-
53
  당신은 μ „λ¬Έκ°€λ‘œμ„œ 쑰언을 ν•˜κ³ , λ§ˆμ§€λ§‰μ— 두 κ°€μ§€λ₯Ό λ°˜λ“œμ‹œ ν¬ν•¨ν•˜μ„Έμš”:
54
- 1. [TAB]: μŒμ•…μ˜ κ°„λ‹¨ν•œ μ•…λ³΄λ‚˜ μ½”λ“œ 진행을 ν…μŠ€νŠΈ ν˜•μ‹μœΌλ‘œ κ·Έλ¦¬μ„Έμš”.
55
- 예: | Am - F - C - G |
56
- 2. [MUSIC]: 뢄야에 νŠΉν™”λœ 고음질 μŒμ•… ν”„λ‘¬ν”„νŠΈλ₯Ό μ μœΌμ„Έμš”.
57
- (High-quality, studio recording, master audio ν•„μˆ˜ 포함)
58
  """
59
 
60
  url = f"https://generativelanguage.googleapis.com/v1beta/models/{ACTIVE_MODEL}:generateContent?key={GENAI_KEY}"
@@ -62,28 +59,29 @@ async def band_consulting(user_input, member_name, consult_category):
62
  res = requests.post(url, json=payload)
63
  ai_text_raw = res.json()['candidates'][0]['content']['parts'][0]['text']
64
 
65
- # 악보([TAB])와 μŒμ•…([MUSIC]) μΆ”μΆœ
66
  tab_match = re.search(r'\[TAB\](.*?)\[', ai_text_raw + '[', re.DOTALL)
67
  music_match = re.search(r'\[MUSIC:(.*?)\]', ai_text_raw, re.IGNORECASE)
68
 
69
- tab_display = tab_match.group(1).strip() if tab_match else "No Score Available"
70
- clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL)
71
- clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
 
 
 
72
 
73
- # 1. λͺ©μ†Œλ¦¬ 생성
74
  voice_path = f"/tmp/v_{member_name}.mp3"
75
- await edge_tts.Communicate(clean_text, member['voice']).save(voice_path)
76
 
77
- # 2. μŒμ•… 생성 (음질 보정 트릭 적용)
78
  music_path = None
79
  if music_match and music_synthesiser:
80
- p = music_match.group(1).strip() + ", high quality, studio recording, clear sound"
81
- # 음질 보정: guidance_scale을 λ†’μ—¬ ν”„λ‘¬ν”„νŠΈ 좩싀도 ν–₯상
82
- music = music_synthesiser(p, forward_params={"max_new_tokens": 448, "guidance_scale": 4.5, "do_sample": True})
83
  music_path = f"/tmp/m_{member_name}.wav"
84
  scipy.io.wavfile.write(music_path, music["sampling_rate"], music["audio"][0].T)
85
 
86
- return clean_text, voice_path, music_path, tab_display
87
 
88
  except Exception as e:
89
  return f"Error: {e}", None, None, ""
 
40
  "Chloe (USA)": { "voice": "en-US-AriaNeural", "prompt": "You are 'Chloe', the guitarist. Speak in English. Focus on guitar tabs and tones." },
41
  "Beatrice (Brazil)": { "voice": "pt-BR-FranciscaNeural", "prompt": "You are 'Beatrice', the drummer. Focus on rhythm patterns and groovy beats." }
42
  }
43
+ # app.py의 band_consulting ν•¨μˆ˜ λΆ€λΆ„λ§Œ 이 λ‚΄μš©μœΌλ‘œ κ΅μ²΄ν•˜μ„Έμš”
44
  async def band_consulting(user_input, member_name, consult_category):
45
  try:
46
+ # 멀버 이름 μ˜€νƒ€ μˆ˜μ •
47
  member = MEMBERS.get(member_name, MEMBERS["μ„œμœ€ (Korea)"])
48
 
 
49
  system_instruction = f"""
50
  {member['prompt']}
51
  [상담 λΆ„μ•Ό: {consult_category}]
 
52
  당신은 μ „λ¬Έκ°€λ‘œμ„œ 쑰언을 ν•˜κ³ , λ§ˆμ§€λ§‰μ— 두 κ°€μ§€λ₯Ό λ°˜λ“œμ‹œ ν¬ν•¨ν•˜μ„Έμš”:
53
+ 1. [TAB]: μŒμ•…μ˜ κ°„λ‹¨ν•œ μ•…λ³΄λ‚˜ μ½”λ“œ 진행을 ν…μŠ€νŠΈ ν˜•μ‹μœΌλ‘œ κ·Έλ¦¬μ„Έμš”.
54
+ 2. [MUSIC]: 뢄야에 νŠΉν™”λœ 고음질 μŒμ•… ν”„λ‘¬ν”„νŠΈλ₯Ό μ μœΌμ„Έμš”.
 
 
55
  """
56
 
57
  url = f"https://generativelanguage.googleapis.com/v1beta/models/{ACTIVE_MODEL}:generateContent?key={GENAI_KEY}"
 
59
  res = requests.post(url, json=payload)
60
  ai_text_raw = res.json()['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)
64
 
65
+ tab_display = tab_match.group(1).strip() if tab_match else "No Score"
66
+
67
+ # 특수문자 읽기 λ°©μ§€ ν•„ν„° (TTS용 ν…μŠ€νŠΈμ—μ„œ 특수문자 제거)
68
+ raw_clean_text = re.sub(r'\[TAB\].*?(\[|$)', '', ai_text_raw, flags=re.DOTALL)
69
+ raw_clean_text = re.sub(r'\[MUSIC:.*?\]', '', raw_clean_text).strip()
70
+ tts_text = re.sub(r'[\*\#\-\_\~]', '', raw_clean_text) # μ„œμœ€μ΄κ°€ 읽을 λ•Œ λ³„ν‘œ 등을 λ¬΄μ‹œν•¨
71
 
72
+ # 1. λͺ©μ†Œλ¦¬ 생성 (ν•„ν„°λ§λœ tts_text μ‚¬μš©)
73
  voice_path = f"/tmp/v_{member_name}.mp3"
74
+ await edge_tts.Communicate(tts_text, member['voice']).save(voice_path)
75
 
76
+ # 2. μŒμ•… 생성
77
  music_path = None
78
  if music_match and music_synthesiser:
79
+ p = music_match.group(1).strip() + ", high quality, studio recording"
80
+ music = music_synthesiser(p, forward_params={"max_new_tokens": 448, "guidance_scale": 4.5})
 
81
  music_path = f"/tmp/m_{member_name}.wav"
82
  scipy.io.wavfile.write(music_path, music["sampling_rate"], music["audio"][0].T)
83
 
84
+ return raw_clean_text, voice_path, music_path, tab_display
85
 
86
  except Exception as e:
87
  return f"Error: {e}", None, None, ""