File size: 3,111 Bytes
4a55d40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cae1258
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

    import gradio as gr
    from musicgen_utils import (
        generate_music_prompt,
        remix_music,
        generate_random,
        category_to_text,
        generate_tone,
        export_midi_file
    )

    categories = [
        "Bird Chirping", "Flute Solo", "Guitar Riff", "Drum Loop",
        "Harmonium Chant", "Piano Arpeggio", "Violin Ambient",
        "Bass Groove", "Ambient Forest", "Temple Bells"
    ]

    with gr.Blocks(title="๐ŸŽผ AI Music & Tone Generator") as demo:
        gr.Markdown("# ๐ŸŽต AI Music Generator
_Easy, beginner-friendly audio & tone creation_")

        with gr.Tabs():
            with gr.Tab("๐ŸŽง Music from Prompt"):
                with gr.Row():
                    category = gr.Dropdown(choices=categories, label="๐ŸŽผ Choose Instrument Category")
                    prompt = gr.Textbox(lines=2, placeholder="Describe your music...", label="Prompt")
                with gr.Row():
                    mood = gr.Radio(["Happy", "Sad", "Calm", "Epic"], label="Mood", value="Calm")
                    tempo = gr.Slider(60, 180, step=5, value=100, label="Tempo (BPM)")
                    duration = gr.Slider(5, 30, step=1, value=10, label="Duration (seconds)")
                    remix_strength = gr.Slider(0.5, 1.5, step=0.1, value=1.0, label="Remix Intensity")

                with gr.Row():
                    btn_gen = gr.Button("๐ŸŽถ Generate Music")
                    btn_remix = gr.Button("๐Ÿช„ AI Remix")
                    btn_rand = gr.Button("๐ŸŽฒ Randomize")

                output_audio = gr.Audio(label="Output Music")
                category.change(fn=category_to_text, inputs=category, outputs=prompt)
                btn_gen.click(fn=generate_music_prompt, inputs=[prompt, mood, tempo, duration, remix_strength], outputs=output_audio)
                btn_remix.click(fn=remix_music, inputs=[prompt, mood, tempo], outputs=output_audio)
                btn_rand.click(fn=generate_random, outputs=output_audio)

            with gr.Tab("๐ŸŽน Tone Synth (Fallback)"):
                with gr.Row():
                    wave = gr.Radio(["Sine", "Square", "Saw", "Triangle"], label="Waveform", value="Sine")
                    freq = gr.Slider(100, 2000, value=440, step=10, label="Frequency (Hz)")
                    duration2 = gr.Slider(1, 10, value=3, step=1, label="Duration (sec)")
                    volume = gr.Slider(0.1, 1.0, value=0.5, step=0.1, label="Volume")

                with gr.Row():
                    bass = gr.Slider(-10, 10, value=0, label="Bass")
                    mid = gr.Slider(-10, 10, value=0, label="Mid")
                    treble = gr.Slider(-10, 10, value=0, label="Treble")

                btn_tone = gr.Button("๐ŸŽผ Generate Tone")
                audio_out = gr.Audio(label="Tone Output")
                midi_out = gr.File(label="Download MIDI")

                btn_tone.click(fn=generate_tone, inputs=[wave, freq, duration2, volume, bass, mid, treble], outputs=audio_out)
                btn_tone.click(fn=export_midi_file, inputs=[freq, duration2], outputs=midi_out)

    demo.launch()