Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,51 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
-
from
|
| 5 |
import librosa
|
| 6 |
import torch
|
| 7 |
import numpy as np
|
| 8 |
|
| 9 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
if torch.cuda.is_available():
|
| 11 |
torch.cuda.empty_cache()
|
| 12 |
|
| 13 |
# MARS5 TTS 모델 로드
|
| 14 |
try:
|
| 15 |
mars5 = Mars5TTS.from_pretrained("CAMB-AI/MARS5-TTS")
|
| 16 |
-
config = InferenceConfig(temperature=0.7)
|
| 17 |
except Exception as e:
|
| 18 |
print(f"Model loading error: {str(e)}")
|
| 19 |
raise
|
| 20 |
|
| 21 |
def clone_with_prosody(text, ref_audio, enhance_prosody=True):
|
| 22 |
-
"""
|
| 23 |
-
입력 텍스트와 참조 오디오를 받아 말투를 클론하여 오디오 출력
|
| 24 |
-
:param text: 변환할 텍스트
|
| 25 |
-
:param ref_audio: 말투를 복제할 오디오 파일 (3-5초 이상 권장)
|
| 26 |
-
:param enhance_prosody: Prosody(억양/리듬) 강조 여부
|
| 27 |
-
:return: 출력 오디오 파일 경로
|
| 28 |
-
"""
|
| 29 |
try:
|
| 30 |
-
# 참조 오디오 로드 (Gradio에서 제공된 filepath 처리)
|
| 31 |
if isinstance(ref_audio, str):
|
| 32 |
-
audio_data, sr = librosa.load(ref_audio, sr=16000)
|
| 33 |
else:
|
| 34 |
-
audio_data = ref_audio
|
| 35 |
|
| 36 |
-
# MARS5 TTS로 클로닝
|
| 37 |
output_audio = mars5.tts(
|
| 38 |
text=text,
|
| 39 |
ref_audio=audio_data,
|
| 40 |
-
ref_sr=16000,
|
| 41 |
-
config=config if enhance_prosody else None,
|
| 42 |
-
language="ko"
|
| 43 |
)
|
| 44 |
|
| 45 |
-
# 출력 오디오 저장
|
| 46 |
output_path = "output_cloned_audio.wav"
|
| 47 |
output_audio.save(output_path)
|
| 48 |
return output_path
|
| 49 |
except Exception as e:
|
| 50 |
return f"Error: {str(e)}"
|
| 51 |
|
| 52 |
-
# Gradio 인터페이스 설정
|
| 53 |
interface = gr.Interface(
|
| 54 |
fn=clone_with_prosody,
|
| 55 |
inputs=[
|
|
@@ -63,5 +59,4 @@ interface = gr.Interface(
|
|
| 63 |
allow_flagging="never"
|
| 64 |
)
|
| 65 |
|
| 66 |
-
# 앱 실행
|
| 67 |
interface.launch()
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
| 3 |
import gradio as gr
|
| 4 |
+
from inference import Mars5TTS, InferenceConfig
|
| 5 |
import librosa
|
| 6 |
import torch
|
| 7 |
import numpy as np
|
| 8 |
|
| 9 |
+
# requirements.txt 설치 확인
|
| 10 |
+
try:
|
| 11 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
|
| 12 |
+
print("Successfully installed requirements.txt")
|
| 13 |
+
except subprocess.CalledProcessError as e:
|
| 14 |
+
print(f"Failed to install requirements.txt: {e}")
|
| 15 |
+
|
| 16 |
+
# GPU 메모리 초기화
|
| 17 |
if torch.cuda.is_available():
|
| 18 |
torch.cuda.empty_cache()
|
| 19 |
|
| 20 |
# MARS5 TTS 모델 로드
|
| 21 |
try:
|
| 22 |
mars5 = Mars5TTS.from_pretrained("CAMB-AI/MARS5-TTS")
|
| 23 |
+
config = InferenceConfig(temperature=0.7)
|
| 24 |
except Exception as e:
|
| 25 |
print(f"Model loading error: {str(e)}")
|
| 26 |
raise
|
| 27 |
|
| 28 |
def clone_with_prosody(text, ref_audio, enhance_prosody=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
try:
|
|
|
|
| 30 |
if isinstance(ref_audio, str):
|
| 31 |
+
audio_data, sr = librosa.load(ref_audio, sr=16000)
|
| 32 |
else:
|
| 33 |
+
audio_data = ref_audio
|
| 34 |
|
|
|
|
| 35 |
output_audio = mars5.tts(
|
| 36 |
text=text,
|
| 37 |
ref_audio=audio_data,
|
| 38 |
+
ref_sr=16000,
|
| 39 |
+
config=config if enhance_prosody else None,
|
| 40 |
+
language="ko"
|
| 41 |
)
|
| 42 |
|
|
|
|
| 43 |
output_path = "output_cloned_audio.wav"
|
| 44 |
output_audio.save(output_path)
|
| 45 |
return output_path
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error: {str(e)}"
|
| 48 |
|
|
|
|
| 49 |
interface = gr.Interface(
|
| 50 |
fn=clone_with_prosody,
|
| 51 |
inputs=[
|
|
|
|
| 59 |
allow_flagging="never"
|
| 60 |
)
|
| 61 |
|
|
|
|
| 62 |
interface.launch()
|