Spaces:
Sleeping
Sleeping
File size: 2,155 Bytes
ea61cad f6b5965 ea61cad f6b5965 2336a37 f6b5965 ea61cad f6b5965 ea61cad f6b5965 ea61cad f6b5965 ea61cad f6b5965 2336a37 f6b5965 c411502 ea61cad f6b5965 ea61cad f6b5965 ea61cad 2336a37 ea61cad 2336a37 ea61cad | 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 60 61 62 63 64 65 66 67 68 69 | import gradio as gr
from transformers import pipeline
import torch
import numpy as np
# Load Tom's brain (MusicGen-Small)
# Using cpu for Hugging Face Free Tier compatibility
synthesiser = pipeline("text-to-audio", "facebook/musicgen-small", device="cpu")
# Your requested Clean UI CSS
custom_css = """
footer {display: none !important;}
.show-api {display: none !important;}
button.reference {display: none !important;}
"""
def tom_make_music(prompt, duration):
if not prompt:
return None
# 50 tokens = ~1 second of audio
max_tokens = int(duration * 50)
output = synthesiser(
prompt,
forward_params={
"do_sample": True,
"max_new_tokens": max_tokens
}
)
return (output["sampling_rate"], output["audio"].squeeze())
# Build the Interface
# NOTE: css removed from here for Gradio 6.0
with gr.Blocks(title="Tom The Music AI") as demo:
gr.Markdown("# 🎹 Tom-The-Ai-Music-AI")
gr.Markdown("I'm Tom. Describe a song and I'll generate it for you. (IMPORTANT: The is Beta Version, Which means it might not work as you want)")
with gr.Row():
with gr.Column():
input_text = gr.Textbox(
label="What should I play?",
placeholder="e.g., Chill lo-fi beats for studying",
lines=3
)
duration_slider = gr.Slider(
minimum=2, maximum=15, value=8, step=1, label="Seconds"
)
btn = gr.Button("Generate with Tom", variant="primary")
with gr.Column():
output_audio = gr.Audio(label="Tom's Masterpiece")
# api_visibility="undocumented" hides this specific function from the API docs
btn.click(
fn=tom_make_music,
inputs=[input_text, duration_slider],
outputs=output_audio,
api_visibility="undocumented"
)
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
css=custom_css, # CSS is now passed here
footer_links=[] # Replaces show_api=False to hide the entire footer
) |