Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,51 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import jukebox
|
3 |
+
import torch as t
|
4 |
+
import librosa
|
5 |
+
import os
|
6 |
+
from IPython.display import Audio
|
7 |
|
8 |
+
# Import the model
|
9 |
+
model = jukebox.make_vqvae(MODELS.5B_LYRICS)
|
10 |
|
11 |
+
# Generate music
|
12 |
+
def generate_music(temperature=1.0, top_k=10, beam_width=5):
|
13 |
+
z = torch.randn(1, 1024)
|
14 |
+
audio = model.sample(z, temperature=temperature, top_k=top_k, beam_width=beam_width)
|
15 |
+
return audio
|
16 |
|
17 |
+
# Input audio
|
18 |
+
def input_audio():
|
19 |
+
audio_file = input("Enter the path to the audio file: ")
|
20 |
+
audio_data = librosa.load(audio_file)
|
21 |
+
return audio_data
|
22 |
|
23 |
+
# Generate music from the input audio
|
24 |
+
def generate_music_from_audio(audio_data):
|
25 |
+
z = model.encode(audio_data)
|
26 |
+
audio = model.decode(z)
|
27 |
+
return audio
|
28 |
+
|
29 |
+
# Save the music
|
30 |
+
def save_music(audio, filename):
|
31 |
+
librosa.output(filename, audio, sr=44100)
|
32 |
+
|
33 |
+
# Play the music
|
34 |
+
def play_music(audio):
|
35 |
+
Audio(audio)
|
36 |
+
|
37 |
+
# Create the Gradio interface
|
38 |
+
app = gr.Interface(
|
39 |
+
generate_music,
|
40 |
+
inputs=[gr.inputs.Slider(label="Temperature", min=0.0, max=1.0, step=0.1),
|
41 |
+
gr.inputs.Slider(label="Top K", min=1, max=10, step=1),
|
42 |
+
gr.inputs.Slider(label="Beam Width", min=1, max=10, step=1)],
|
43 |
+
outputs=gr.outputs.Audio(),
|
44 |
+
title="OpenAI Jukebox",
|
45 |
+
description="Generate music using OpenAI Jukebox",
|
46 |
+
allow_screenshot=True,
|
47 |
+
clear_output=True
|
48 |
+
)
|
49 |
+
|
50 |
+
# Run the app
|
51 |
+
app.launch()
|