Spaces:
Sleeping
Sleeping
ghostofdivinity
commited on
Commit
·
910b02d
1
Parent(s):
bbd0842
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
import torch
|
4 |
import torchaudio
|
|
|
|
|
5 |
from torch import nn
|
6 |
-
from torch.utils.data import DataLoader, Dataset
|
7 |
-
from torchvision import transforms
|
8 |
-
import numpy as np
|
9 |
-
import IPython.display as ipd
|
10 |
-
|
11 |
-
# Generate new kick drum samples
|
12 |
-
generator.eval()
|
13 |
-
with torch.no_grad():
|
14 |
-
for i in range(num_generated_samples):
|
15 |
-
noise = torch.randn(1, latent_dim).to(device)
|
16 |
-
generated_sample = generator(noise).squeeze().cpu()
|
17 |
-
|
18 |
-
# Save the generated sample
|
19 |
-
output_filename = f"generated_kick_{i+1}.wav"
|
20 |
-
torchaudio.save(output_filename, generated_sample.unsqueeze(0), 16000)
|
21 |
-
|
22 |
-
# Play the generated sample
|
23 |
-
print(f"Generated Sample {i+1}:")
|
24 |
-
display(ipd.Audio(output_filename))
|
25 |
|
26 |
# Load the saved generator model
|
27 |
class Generator(nn.Module):
|
@@ -39,11 +21,13 @@ class Generator(nn.Module):
|
|
39 |
def forward(self, x):
|
40 |
return self.generator(x)
|
41 |
|
|
|
42 |
latent_dim = 100
|
43 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
44 |
generator = Generator(latent_dim).to(device)
|
45 |
-
generator_model_path =
|
46 |
-
generator.load_state_dict(torch.load(generator_model_path))
|
|
|
47 |
|
48 |
def generate_kick_drums():
|
49 |
# Define the number of samples you want to generate
|
@@ -65,10 +49,11 @@ def generate_kick_drums():
|
|
65 |
|
66 |
return tuple(output_files)
|
67 |
|
|
|
68 |
def gradio_interface():
|
69 |
generate_button = gr.Interface(fn=generate_kick_drums,
|
70 |
inputs=None,
|
71 |
-
outputs=[gr.Audio(type='filepath', label=f"generated_kick_{i
|
72 |
live=True)
|
73 |
generate_button.launch(debug=True)
|
74 |
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import torch
|
3 |
import torchaudio
|
4 |
+
from google.colab import drive
|
5 |
+
drive.mount('/content/drive')
|
6 |
from torch import nn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# Load the saved generator model
|
9 |
class Generator(nn.Module):
|
|
|
21 |
def forward(self, x):
|
22 |
return self.generator(x)
|
23 |
|
24 |
+
|
25 |
latent_dim = 100
|
26 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
27 |
generator = Generator(latent_dim).to(device)
|
28 |
+
generator_model_path = '/content/drive/MyDrive/generator_model.pkl'
|
29 |
+
generator.load_state_dict(torch.load(generator_model_path, map_location=device))
|
30 |
+
|
31 |
|
32 |
def generate_kick_drums():
|
33 |
# Define the number of samples you want to generate
|
|
|
49 |
|
50 |
return tuple(output_files)
|
51 |
|
52 |
+
# Define Gradio interface
|
53 |
def gradio_interface():
|
54 |
generate_button = gr.Interface(fn=generate_kick_drums,
|
55 |
inputs=None,
|
56 |
+
outputs=[gr.Audio(type='filepath', label=f"generated_kick_{i}") for i in range(3)],
|
57 |
live=True)
|
58 |
generate_button.launch(debug=True)
|
59 |
|