Spaces:
Sleeping
Sleeping
import gradio as gr | |
from huggingface_hub import cached_download, hf_hub_url | |
import torch | |
from transformers import pipeline | |
model_id = "facebook/musicgen-medium" | |
audiogen = pipeline("text-to-audio", model=model_id) | |
def generate_audio(text, duration): | |
audio = audiogen(text, duration=duration) | |
return audio.audio | |
with gr.Blocks() as demo: | |
gr.Markdown( | |
""" | |
# Генератор музыки из текста | |
""" | |
) | |
with gr.Row(): | |
text_input = gr.Textbox(label="Введите текст для генерации музыки:") | |
duration_slider = gr.Slider( | |
minimum=2, maximum=30, value=10, label="Длина аудио (сек.):" | |
) | |
generate_button = gr.Button("Сгенерировать музыку") | |
audio_output = gr.Audio(label="Результат:") | |
generate_button.click( | |
fn=generate_audio, | |
inputs=[text_input, duration_slider], | |
outputs=audio_output, | |
) | |
demo.launch() |