Spaces:
Runtime error
Runtime error
File size: 1,562 Bytes
fd7a397 6134fc9 465ee60 6134fc9 fd7a397 b2d4aa4 fd7a397 b2d4aa4 465ee60 6e5a5d5 fd7a397 e446f13 6134fc9 fd7a397 98c6a7f 6134fc9 98c6a7f a665630 17bdca8 98c6a7f 6134fc9 fd7a397 6134fc9 fd7a397 17bdca8 955abc0 fd7a397 60d3210 |
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 48 49 50 51 52 53 54 55 56 57 58 59 |
from diffusers import AudioLDMPipeline
import torch
import gradio as gr
from transformers import pipeline
#from googletrans import Translator
import os
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 = pipe.to(device)
# pipe.unet = torch.compile(pipe.unet)
#pipe.unet = torch.compile(pipe.unet)
def generate_sound(text):
print(text)
# text=translate_text(text)
text = translate_text(text)
#translator = Translator()
#text=translator.translate(text, src='es',dest="en").text
print(text)
waveforms = pipe(text,
num_inference_steps=25,
audio_length_in_s=5,
negative_prompt = "low quality, average quality").audios
rate =16000
return rate, waveforms[0]
#return gr.make_waveform((rate, waveforms[0]))
es_en_translator = pipeline("translation",model = "Helsinki-NLP/opus-mt-es-en")
def translate_text(text):
text = es_en_translator(text)[0].get("translation_text")
return 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()
#output = gr.Video(label="Output")
button.click(generate_sound,text,output)
demo.launch() |