benjamin5607 commited on
Commit
6ef5c24
Β·
verified Β·
1 Parent(s): 474efb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -17
app.py CHANGED
@@ -4,19 +4,8 @@ import edge_tts
4
  import os
5
  import re
6
  import scipy.io.wavfile
7
- import asyncio
8
- import numpy as np
9
  from transformers import pipeline
10
 
11
- # [핡심] 비동기 파일 λ””μŠ€ν¬λ¦½ν„° μ—λŸ¬ λ°©μ§€ μ„€μ •
12
- if os.name != 'nt': # λ¦¬λˆ…μŠ€/λ§₯ ν™˜κ²½ λŒ€μ‘
13
- import selectors
14
- selector = selectors.SelectSelector()
15
- try:
16
- asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
17
- except:
18
- pass
19
-
20
  GENAI_KEY = os.getenv("GEMINI_KEY")
21
 
22
  # μŒμ•… λͺ¨λΈ λ‘œλ“œ
@@ -70,17 +59,17 @@ async def band_consulting(user_input, member_name, lang_code):
70
  clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
71
  music_p = music_match.group(1).strip() if music_match else "rock guitar riff"
72
 
73
- # μŒμ„± 생성 (비동기 루프 직접 μ œμ–΄)
74
  tts_final = "\n".join(clean_text.split('\n')[:5])
75
  voice_path = f"/tmp/v_{member_name.split()[0]}.mp3"
76
- # 파일이 μ—΄λ €μžˆλŠ”μ§€ 확인 ν›„ 생성
77
  communicate = edge_tts.Communicate(re.sub(r'[\*\#\-\_\~\|]', '', tts_final), member_data['voice'])
78
  await communicate.save(voice_path)
79
 
80
- # μŒμ•… 생성 (512 토큰 ν’€ νŒŒμ›Œ)
81
  music_path = None
82
  if music_synthesiser:
83
  try:
 
84
  safe_p = music_p.lower()
85
  if any(x in safe_p for x in ['laugh', 'vocal', 'voice', 'human']):
86
  safe_p = "heavy rock electric guitar riff"
@@ -95,13 +84,13 @@ async def band_consulting(user_input, member_name, lang_code):
95
  return tts_final, voice_path, music_path, tab_display
96
 
97
  except Exception as e:
98
- print(f"Error caught: {e}")
99
  return f"System Overload: {str(e)}", None, None, "Error"
100
 
101
  with gr.Blocks() as demo:
 
102
  i1 = gr.Textbox(); i2 = gr.Textbox(); i3 = gr.Textbox()
103
  o1 = gr.Textbox(); o2 = gr.Audio(); o3 = gr.Audio(); o4 = gr.Textbox()
104
  btn = gr.Button("GO"); btn.click(band_consulting, [i1, i2, i3], [o1, o2, o3, o4], api_name="predict")
105
 
106
- # 큐 μ‹œμŠ€ν…œμœΌλ‘œ νƒ€μž„μ•„μ›ƒ λ°©μ§€
107
- demo.queue().launch()
 
4
  import os
5
  import re
6
  import scipy.io.wavfile
 
 
7
  from transformers import pipeline
8
 
 
 
 
 
 
 
 
 
 
9
  GENAI_KEY = os.getenv("GEMINI_KEY")
10
 
11
  # μŒμ•… λͺ¨λΈ λ‘œλ“œ
 
59
  clean_text = re.sub(r'\[MUSIC:.*?\]', '', clean_text).strip()
60
  music_p = music_match.group(1).strip() if music_match else "rock guitar riff"
61
 
62
+ # μŒμ„± 생성
63
  tts_final = "\n".join(clean_text.split('\n')[:5])
64
  voice_path = f"/tmp/v_{member_name.split()[0]}.mp3"
 
65
  communicate = edge_tts.Communicate(re.sub(r'[\*\#\-\_\~\|]', '', tts_final), member_data['voice'])
66
  await communicate.save(voice_path)
67
 
68
+ # μŒμ•… 생성
69
  music_path = None
70
  if music_synthesiser:
71
  try:
72
+ # ν•„ν„° 단어 우회 및 길이 쑰절 (12초)
73
  safe_p = music_p.lower()
74
  if any(x in safe_p for x in ['laugh', 'vocal', 'voice', 'human']):
75
  safe_p = "heavy rock electric guitar riff"
 
84
  return tts_final, voice_path, music_path, tab_display
85
 
86
  except Exception as e:
 
87
  return f"System Overload: {str(e)}", None, None, "Error"
88
 
89
  with gr.Blocks() as demo:
90
+ # API μ „μš© μ΅œμ†Œ UI (λͺ¨λ“  λ‘œμ§μ€ predict둜 μ—°κ²°)
91
  i1 = gr.Textbox(); i2 = gr.Textbox(); i3 = gr.Textbox()
92
  o1 = gr.Textbox(); o2 = gr.Audio(); o3 = gr.Audio(); o4 = gr.Textbox()
93
  btn = gr.Button("GO"); btn.click(band_consulting, [i1, i2, i3], [o1, o2, o3, o4], api_name="predict")
94
 
95
+ # 큐 μ‹œμŠ€ν…œμ„ μ μš©ν•˜λ˜ ssr_modeλŠ” False둜 μ„€μ •ν•˜μ—¬ asyncio μ—λŸ¬ λ°©μ§€
96
+ demo.queue().launch(ssr_mode=False)