Spaces:
Runtime error
Runtime error
File size: 1,239 Bytes
fd7a397 b2d4aa4 fd7a397 b2d4aa4 6e5a5d5 fd7a397 98c6a7f fd7a397 98c6a7f fd7a397 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
from diffusers import AudioLDMPipeline
import torch
import gradio as gr
from googletrans import Translator
if torch.cuda.is_available():
device = "cuda"
torch_dtype = torch.float16
else:
device = "cpu"
torch_dtype = torch.float32
print(device)
repo_id = "cvssp/audioldm-m-full"
pipe = AudioLDMPipeline.from_pretrained(repo_id, torch_dtype=torch_dtype)
#pipe.unet = torch.compile(pipe.unet)
def generate_sound(text):
print(text)
text=translate_text(text)
print(text)
waveforms = pipe(text,
num_inference_steps=25,
audio_length_in_s=5,
negative_prompt = "low quality, average quality").audios
rate =160000
#return rate, audio
return gr.make_waveform((rate, waveforms[0]))
def translate_text(text):
translator = Translator()
translated_text=translator.translate(text, src='es',dest="en")
return translated_text.text
demo = gr.Blocks()
with demo:
with gr.Row():
with gr.Column():
text = gr.Textbox(value="Ingrese el texto:")
button = gr.Button(value="Generar")
with gr.Column():
output = gr.Audio()
button.click(generate_sound,text,output)
demo.launch() |