Spaces:
Runtime error
Runtime error
| 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() | |