Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import replicate
|
| 3 |
+
|
| 4 |
+
def generate_music(genre, instruments, tempo, mood, duration, key_scale):
|
| 5 |
+
# Creating a more detailed prompt based on the additional options
|
| 6 |
+
prompt = f"Generate a {genre} track featuring {instruments}, in a {mood} mood, with a consistent melody throughout, with a tempo of {tempo} BPM, in the key of {key_scale}."
|
| 7 |
+
# Assuming replicate.run() is a placeholder for actual music generation API call
|
| 8 |
+
# Please replace with the actual function call to generate music
|
| 9 |
+
output = replicate.run(
|
| 10 |
+
"bamartin1618/weather-channel:77dae70c23138abd20014ba686f62da780c5aed738e00085ce698eb5e344c65a",
|
| 11 |
+
input={
|
| 12 |
+
"top_k": 250,
|
| 13 |
+
"top_p": 1,
|
| 14 |
+
"prompt": prompt,
|
| 15 |
+
"duration": duration,
|
| 16 |
+
"temperature": 1,
|
| 17 |
+
"continuation": False,
|
| 18 |
+
"output_format": "wav",
|
| 19 |
+
"continuation_start": 0,
|
| 20 |
+
"multi_band_diffusion": False,
|
| 21 |
+
"normalization_strategy": "loudness",
|
| 22 |
+
"classifier_free_guidance": 6
|
| 23 |
+
}
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
if output:
|
| 27 |
+
return f'<a href="{output}" target="_blank">Click here to listen to the generated music</a>'
|
| 28 |
+
else:
|
| 29 |
+
return 'Music generation failed or no URL returned.'
|
| 30 |
+
|
| 31 |
+
def get_audio_path(selection):
|
| 32 |
+
# Map selection to your audio file URLs
|
| 33 |
+
audio_files = {
|
| 34 |
+
"Smooth Jazz Evening": "smooth_jazz_evening.wav",
|
| 35 |
+
"Uplifting Soft Rock": "uplifting_soft_rock.wav",
|
| 36 |
+
"Mellow Jazz Morning": "mellow_jazz_morning.wav",
|
| 37 |
+
"Soft Rock Serenade": "soft_rock_serenade.wav",
|
| 38 |
+
}
|
| 39 |
+
return audio_files[selection]
|
| 40 |
+
|
| 41 |
+
with gr.Blocks() as app:
|
| 42 |
+
with gr.Tab("Generate Music"):
|
| 43 |
+
genre = gr.Dropdown(["Smooth Jazz", "Soft Rock"], label="Genre")
|
| 44 |
+
instruments = gr.CheckboxGroup(["Piano", "Saxophone", "Guitar", "Strings"], label="Instruments")
|
| 45 |
+
tempo = gr.Slider(minimum=60, maximum=180, step=5, value=120, label="Tempo (BPM)")
|
| 46 |
+
mood = gr.Dropdown(["Relaxing", "Cheerful"], label="Mood")
|
| 47 |
+
duration = gr.Slider(minimum=1, maximum=20, step=1, value=15, label="Duration (Seconds)")
|
| 48 |
+
key_scale = gr.Dropdown(["C Major", "A Minor", "G Major", "E Minor"], label="Key & Scale")
|
| 49 |
+
generate_btn = gr.Button("Generate")
|
| 50 |
+
generate_btn.click(
|
| 51 |
+
generate_music,
|
| 52 |
+
inputs=[genre, instruments, tempo, mood, duration, key_scale],
|
| 53 |
+
outputs=gr.HTML()
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
with gr.Tab("Samples"):
|
| 57 |
+
audio_selection = gr.Radio(
|
| 58 |
+
["Smooth Jazz Evening", "Uplifting Soft Rock", "Mellow Jazz Morning", "Soft Rock Serenade"],
|
| 59 |
+
label="Select Music Sample"
|
| 60 |
+
)
|
| 61 |
+
play_audio_btn = gr.Button("Play Audio")
|
| 62 |
+
preloaded_audio_output = gr.Audio(label="Preloaded Audio")
|
| 63 |
+
play_audio_btn.click(
|
| 64 |
+
get_audio_path,
|
| 65 |
+
inputs=audio_selection,
|
| 66 |
+
outputs=preloaded_audio_output
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
app.launch()
|