File size: 2,516 Bytes
c68d858
48ec548
360cfe5
 
c68d858
360cfe5
 
 
 
 
0f2f467
 
360cfe5
 
0f2f467
 
360cfe5
 
 
 
 
 
 
 
 
 
4df9332
360cfe5
9a1279a
 
360cfe5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ac1d8f
360cfe5
 
 
 
 
 
 
 
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
70
import spaces
import gradio as gr
import os
from model import Jamify

# Initialize the Jamify model once
print("Initializing Jamify model...")
jamify_model = Jamify()
print("Jamify model ready.")


@spaces.GPU(duration=100)
def generate_song(reference_audio, lyrics_file, style_prompt, duration):
    # We need to save the uploaded files to temporary paths to pass to the model
    reference_audio = reference_audio if reference_audio else None
    

    # The model expects paths, so we write the prompt to a temp file if needed
    # (This part of the model could be improved to accept the string directly)

    output_path = jamify_model.predict(
        reference_audio_path=ref_audio_path,
        lyrics_json_path=lyrics_path,
        style_prompt=style_prompt,
        duration_sec=duration
    )
    
    return output_path

# Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Jamify: Music Generation from Lyrics and Style")
    gr.Markdown("Provide your lyrics, a style reference (either an audio file or a text prompt), and a desired duration to generate a song.")
    
    with gr.Row():
        with gr.Column():
            gr.Markdown("### Inputs")
            lyrics_file = gr.File(label="Lyrics File (.json)", type="filepath")
            duration_slider = gr.Slider(minimum=5, maximum=180, value=30, step=1, label="Duration (seconds)")
            
            with gr.Tab("Style from Audio"):
                reference_audio = gr.File(label="Reference Audio (.mp3, .wav)", type="filepath")
            with gr.Tab("Style from Text"):
                style_prompt = gr.Textbox(label="Style Prompt", lines=3, placeholder="e.g., A high-energy electronic dance track with a strong bassline and euphoric synths.")
            
            generate_button = gr.Button("Generate Song", variant="primary")
            
        with gr.Column():
            gr.Markdown("### Output")
            output_audio = gr.Audio(label="Generated Song")

    generate_button.click(
        fn=generate_song,
        inputs=[reference_audio, lyrics_file, style_prompt, duration_slider],
        outputs=output_audio,
        api_name="generate_song"
    )

    gr.Markdown("### Example Usage")
    gr.Examples(
        examples=[
            [None, "gt0.json", "A sad, slow, acoustic country song", 30],
        ],
        inputs=[reference_audio, lyrics_file, style_prompt, duration_slider],
        outputs=output_audio,
        fn=generate_song,
        cache_examples=True
    )

demo.queue().launch()