Spaces:
Runtime error
Runtime error
Update back-cod.py
Browse files- back-cod.py +11 -3
back-cod.py
CHANGED
|
@@ -17,7 +17,10 @@ from transformers import CLIPTextModel, T5EncoderModel, AutoModel, T5Tokenizer,
|
|
| 17 |
from typing import Union
|
| 18 |
from diffusers.utils.torch_utils import randn_tensor
|
| 19 |
from tqdm import tqdm
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 21 |
class Tango2Pipeline(DiffusionPipeline):
|
| 22 |
def __init__(
|
| 23 |
self,
|
|
@@ -243,9 +246,14 @@ pipe = Tango2Pipeline(vae=tango.vae,
|
|
| 243 |
|
| 244 |
@spaces.GPU(duration=60)
|
| 245 |
def gradio_generate(prompt, output_format, steps, guidance):
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
output_wave = output_wave.audios[0]
|
| 250 |
output_filename = "temp.wav"
|
| 251 |
wavio.write(output_filename, output_wave, rate=16000, sampwidth=2)
|
|
|
|
| 17 |
from typing import Union
|
| 18 |
from diffusers.utils.torch_utils import randn_tensor
|
| 19 |
from tqdm import tqdm
|
| 20 |
+
from transformers import pipeline
|
| 21 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
| 22 |
|
| 23 |
+
|
| 24 |
class Tango2Pipeline(DiffusionPipeline):
|
| 25 |
def __init__(
|
| 26 |
self,
|
|
|
|
| 246 |
|
| 247 |
@spaces.GPU(duration=60)
|
| 248 |
def gradio_generate(prompt, output_format, steps, guidance):
|
| 249 |
+
# 한글이 포함되어 있는지 확인
|
| 250 |
+
if any(ord('가') <= ord(char) <= ord('힣') for char in prompt):
|
| 251 |
+
# 한글을 영어로 번역
|
| 252 |
+
translation = translator(prompt)[0]['translation_text']
|
| 253 |
+
prompt = translation
|
| 254 |
+
print(f"Translated prompt: {prompt}")
|
| 255 |
+
|
| 256 |
+
output_wave = pipe(prompt,steps,guidance)
|
| 257 |
output_wave = output_wave.audios[0]
|
| 258 |
output_filename = "temp.wav"
|
| 259 |
wavio.write(output_filename, output_wave, rate=16000, sampwidth=2)
|