ginipick commited on
Commit
2792e64
Β·
verified Β·
1 Parent(s): fe0dd07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -30
app.py CHANGED
@@ -200,7 +200,7 @@ def initialize_system():
200
  logging.error(f"Directory error: {e}")
201
  raise
202
 
203
- @lru_cache(maxsize=100)
204
  def get_cached_file_path(content_hash, prefix):
205
  return create_temp_file(content_hash, prefix)
206
 
@@ -232,6 +232,8 @@ def get_last_mp3_file(output_dir):
232
  mp3_files_with_path.sort(key=os.path.getmtime, reverse=True)
233
  return mp3_files_with_path[0]
234
 
 
 
235
  def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
236
  try:
237
  # λͺ¨λΈ 선택 및 μ„€μ •
@@ -269,17 +271,11 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
269
  "--chorus_strength", str(config['chorus_strength'])
270
  ]
271
 
272
- # GPUκ°€ 있고 flash-attn이 μ„€μΉ˜λœ κ²½μš°μ—λ§Œ μΆ”κ°€ μ˜΅μ…˜ 적용
273
  if torch.cuda.is_available():
274
  command.extend([
275
- "--disable_offload_model",
276
- "--bf16"
277
  ])
278
- try:
279
- import flash_attn
280
- command.append("--use_flash_attention_2")
281
- except ImportError:
282
- logging.info("flash-attn not available, skipping flash attention option")
283
 
284
  # CUDA ν™˜κ²½ λ³€μˆ˜ μ„€μ •
285
  env = os.environ.copy()
@@ -293,8 +289,23 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
293
  })
294
 
295
  # λͺ…λ Ή μ‹€ν–‰
296
- process = subprocess.run(command, env=env, check=True, capture_output=True)
297
- logging.info("Inference completed successfully")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
 
299
  # κ²°κ³Ό 처리
300
  last_mp3 = get_last_mp3_file(output_dir)
@@ -372,34 +383,56 @@ def main():
372
  [
373
  "female blues airy vocal bright vocal piano sad romantic guitar jazz",
374
  """[verse]
375
- In the quiet of the evening, shadows start to fall
376
- Whispers of the night wind echo through the hall
377
- Lost within the silence, I hear your gentle voice
378
- Guiding me back homeward, making my heart rejoice
379
 
380
- [chorus]
381
- Don't let this moment fade, hold me close tonight
382
- With you here beside me, everything's alright
383
- Can't imagine life alone, don't want to let you go
384
- Stay with me forever, let our love just flow
385
 
 
 
 
 
 
 
 
 
 
 
 
386
  """
387
  ],
388
  # ν•œκ΅­μ–΄ 예제
389
  [
390
  "K-pop bright energetic synth dance electronic",
391
  """[verse]
392
- λΉ›λ‚˜λŠ” λ³„λ“€μ²˜λŸΌ 우리의 꿈이
393
- μ € ν•˜λŠ˜μ„ μˆ˜λ†“μ•„ λ°˜μ§μ΄λ„€
394
- ν•¨κ»˜λΌλ©΄ μ–΄λ””λ“  갈 수 μžˆμ–΄
395
- 우리의 이야기가 μ‹œμž‘λ˜λ„€
 
 
 
 
 
 
396
 
397
- [chorus]
398
- λ‹¬λ €κ°€μž 더 높이 더 멀리
399
- 두렀움은 μ—†μ–΄ λ„ˆμ™€ ν•¨κ»˜λΌλ©΄
400
- μ˜μ›νžˆ 계속될 우리의 λ…Έλž˜
401
- 이 μˆœκ°„μ„ κΈ°μ–΅ν•΄ forever
402
 
 
 
 
 
 
403
  """
404
  ]
405
  ],
@@ -427,4 +460,4 @@ if __name__ == "__main__":
427
  show_api=True,
428
  show_error=True,
429
  max_threads=2
430
- )
 
200
  logging.error(f"Directory error: {e}")
201
  raise
202
 
203
+ @lru_cache(maxsize=50)
204
  def get_cached_file_path(content_hash, prefix):
205
  return create_temp_file(content_hash, prefix)
206
 
 
232
  mp3_files_with_path.sort(key=os.path.getmtime, reverse=True)
233
  return mp3_files_with_path[0]
234
 
235
+
236
+
237
  def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
238
  try:
239
  # λͺ¨λΈ 선택 및 μ„€μ •
 
271
  "--chorus_strength", str(config['chorus_strength'])
272
  ]
273
 
274
+ # GPUκ°€ μžˆλŠ” κ²½μš°μ—λ§Œ μΆ”κ°€ μ˜΅μ…˜ 적용
275
  if torch.cuda.is_available():
276
  command.extend([
277
+ "--disable_offload_model"
 
278
  ])
 
 
 
 
 
279
 
280
  # CUDA ν™˜κ²½ λ³€μˆ˜ μ„€μ •
281
  env = os.environ.copy()
 
289
  })
290
 
291
  # λͺ…λ Ή μ‹€ν–‰
292
+ process = subprocess.run(
293
+ command,
294
+ env=env,
295
+ check=False,
296
+ capture_output=True,
297
+ text=True
298
+ )
299
+
300
+ # μ‹€ν–‰ κ²°κ³Ό λ‘œκΉ…
301
+ logging.info(f"Command output: {process.stdout}")
302
+ if process.stderr:
303
+ logging.error(f"Command error: {process.stderr}")
304
+
305
+ if process.returncode != 0:
306
+ logging.error(f"Command failed with return code: {process.returncode}")
307
+ logging.error(f"Command: {' '.join(command)}")
308
+ raise RuntimeError(f"Inference failed: {process.stderr}")
309
 
310
  # κ²°κ³Ό 처리
311
  last_mp3 = get_last_mp3_file(output_dir)
 
383
  [
384
  "female blues airy vocal bright vocal piano sad romantic guitar jazz",
385
  """[verse]
386
+ In the quiet of the evening, shadows start to fall
387
+ Whispers of the night wind echo through the hall
388
+ Lost within the silence, I hear your gentle voice
389
+ Guiding me back homeward, making my heart rejoice
390
 
391
+ [chorus]
392
+ Don't let this moment fade, hold me close tonight
393
+ With you here beside me, everything's alright
394
+ Can't imagine life alone, don't want to let you go
395
+ Stay with me forever, let our love just flow
396
 
397
+ [verse]
398
+ Morning light is breaking, through the window pane
399
+ Memories of yesterday, like soft summer rain
400
+ In your arms I'm finding, all I'm dreaming of
401
+ Every day beside you, fills my heart with love
402
+
403
+ [chorus]
404
+ Don't let this moment fade, hold me close tonight
405
+ With you here beside me, everything's alright
406
+ Can't imagine life alone, don't want to let you go
407
+ Stay with me forever, let our love just flow
408
  """
409
  ],
410
  # ν•œκ΅­μ–΄ 예제
411
  [
412
  "K-pop bright energetic synth dance electronic",
413
  """[verse]
414
+ λΉ›λ‚˜λŠ” λ³„λ“€μ²˜λŸΌ 우리의 꿈이
415
+ μ € ν•˜λŠ˜μ„ μˆ˜λ†“μ•„ λ°˜μ§μ΄λ„€
416
+ ν•¨κ»˜λΌλ©΄ μ–΄λ””λ“  갈 수 μžˆμ–΄
417
+ 우리의 이야기가 μ‹œμž‘λ˜λ„€
418
+
419
+ [chorus]
420
+ λ‹¬λ €κ°€μž 더 높이 더 멀리
421
+ 두렀움은 μ—†μ–΄ λ„ˆμ™€ ν•¨κ»˜λΌλ©΄
422
+ μ˜μ›νžˆ 계속될 우리의 λ…Έλž˜
423
+ 이 μˆœκ°„μ„ κΈ°μ–΅ν•΄ forever
424
 
425
+ [verse]
426
+ μƒˆλ‘œμš΄ 내일을 ν–₯ν•΄ λ‚˜μ•„κ°€
427
+ 우리만의 길을 λ§Œλ“€μ–΄κ°€
428
+ 믿음으둜 κ°€λ“ν•œ 우리의 맘
429
+ μ ˆλŒ€ λ©ˆμΆ”μ§€ μ•Šμ•„ κ³„μ†ν•΄μ„œ
430
 
431
+ [chorus]
432
+ λ‹¬λ €κ°€μž 더 높이 더 멀리
433
+ 두렀움은 μ—†μ–΄ λ„ˆμ™€ ν•¨κ»˜λΌλ©΄
434
+ μ˜μ›νžˆ 계속될 우리의 λ…Έλž˜
435
+ 이 μˆœκ°„μ„ κΈ°μ–΅ν•΄ forever
436
  """
437
  ]
438
  ],
 
460
  show_api=True,
461
  show_error=True,
462
  max_threads=2
463
+ )