yourusername commited on
Commit
0da7fa4
•
0 Parent(s):

:tada: init

Browse files
.github/workflows/check_size.yaml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Check file size
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [main]
6
+
7
+ # to run this workflow manually from the Actions tab
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ sync-to-hub:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Check large files
15
+ uses: ActionsDesk/lfs-warning@v2.0
16
+ with:
17
+ filesizelimit: 10485760 # = 10MB, so we can sync to HF spaces
.github/workflows/sync_to_hub.yaml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ # to run this workflow manually from the Actions tab
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ sync-to-hub:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ with:
16
+ fetch-depth: 0
17
+ - name: Push to hub
18
+ env:
19
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
20
+ run: git push https://nateraw:$HF_TOKEN@huggingface.co/spaces/nateraw/spotify-pedalboard-demo main --force
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Spotify Pedalboard Demo
3
+ emoji: 🎶
4
+ colorFrom: blue
5
+ colorTo: red
6
+ sdk: streamlit
7
+ app_file: app/app.py
8
+ pinned: false
9
+ ---
10
+
11
+ # Spotify Pedalboard Demo
12
+
13
+ Autogenerated using [this template](https://github.com/nateraw/spaces-template)
app/__init__.py ADDED
File without changes
app/app.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import soundfile as sf
3
+ from pedalboard import (
4
+ Pedalboard,
5
+ Chorus,
6
+ Compressor,
7
+ Convolution,
8
+ Distortion,
9
+ Gain,
10
+ HighpassFilter,
11
+ LadderFilter,
12
+ Limiter,
13
+ LowpassFilter,
14
+ NoiseGate,
15
+ Phaser,
16
+ Reverb,
17
+ )
18
+
19
+
20
+ objects_and_init_kwargs = [
21
+ (
22
+ Chorus,
23
+ {
24
+ "rate_hz": 1.0,
25
+ "depth": 0.25,
26
+ "centre_delay_ms": 7.0,
27
+ "feedback": 0.0,
28
+ "mix": 0.5,
29
+ },
30
+ ),
31
+ (Compressor, {"threshold_db": 0, "ratio": 1, "attack_ms": 1.0, "release_ms": 100}),
32
+ # TODO - maybe add a few impulse responses to a folder + let folks cycle through them.
33
+ # (Convolution, {'impulse_response_filename': None, 'mix': 1.0}),
34
+ (Distortion, {"drive_db": 25}),
35
+ (Gain, {"gain_db": 1.0}),
36
+ (HighpassFilter, {"cutoff_frequency_hz": 50}),
37
+ (LadderFilter, {"mode": LadderFilter.LPF12, "cutoff_hz": 200, "drive": 1.0}),
38
+ (Limiter, {"threshold_db": -10.0, "release_ms": 100.0}),
39
+ (LowpassFilter, {"cutoff_frequency_hz": 50}),
40
+ (
41
+ NoiseGate,
42
+ {"threshold_db": -100.0, "ratio": 10, "attack_ms": 1.0, "release_ms": 100.0},
43
+ ),
44
+ (
45
+ Phaser,
46
+ {
47
+ "rate_hz": 1.0,
48
+ "depth": 0.5,
49
+ "centre_frequency_hz": 1300.0,
50
+ "feedback": 0.0,
51
+ "mix": 0.5,
52
+ },
53
+ ),
54
+ (
55
+ Reverb,
56
+ {
57
+ "room_size": 0.5,
58
+ "damping": 0.5,
59
+ "wet_level": 0.33,
60
+ "dry_level": 0.4,
61
+ "width": 1.0,
62
+ "freeze_mode": 0.0,
63
+ },
64
+ ),
65
+ ]
66
+
67
+ name_to_object_init_kwargs = {
68
+ obj.__name__: (obj, kwargs) for obj, kwargs in objects_and_init_kwargs
69
+ }
70
+
71
+
72
+ def get_transform_names(augmentations):
73
+ transform_names = [st.sidebar.selectbox("Select transformation â„–1:", augmentations)]
74
+ while transform_names[-1] != "None":
75
+ transform_names.append(
76
+ st.sidebar.selectbox(
77
+ f"Select transformation â„–{len(transform_names) + 1}:",
78
+ ["None"] + augmentations,
79
+ )
80
+ )
81
+ transform_names = transform_names[:-1]
82
+ return transform_names
83
+
84
+
85
+ def get_transforms():
86
+ transform_names = get_transform_names(sorted(name_to_object_init_kwargs.keys()))
87
+
88
+ transforms = []
89
+ for i, name in enumerate(transform_names):
90
+ st.sidebar.markdown("---")
91
+ st.sidebar.markdown(f"#### transformation â„–{i + 1}: {name}")
92
+ obj, kwargs = name_to_object_init_kwargs[name]
93
+
94
+ # 🚨 OMG pls no 🤮. It doesn't have to be this way. Do anything but this. 🚨
95
+ inputs = {}
96
+ for k, v in kwargs.items():
97
+ if k in ["mix", "room_size", "damping", "wet_level", "dry_level", "width", "freeze_mode", 'feedback']:
98
+ x = st.sidebar.slider(k, 0.0, 1.0, 0.1, key=f"{k}_{i}")
99
+ elif k in ['threshold_db', 'gain_db']:
100
+ x = st.sidebar.slider(k, -20., 20., 0., key=f"{k}_{i}")
101
+ elif k in ['rate_hz', 'centre_delay_ms', 'depth']:
102
+ x = st.sidebar.slider(k, 0., 10., 0.5, key=f"{k}_{i}")
103
+ elif k in ['drive_db']:
104
+ x = st.sidebar.slider(k, 0., 20., 0., key=f"{k}_{i}")
105
+ elif k in ['release']:
106
+ x = st.sidebar.slider(k, 0.01, 5000., 100., key=f"{k}_{i}")
107
+ elif k in ['ratio', 'drive']:
108
+ x = st.sidebar.slider(k, 1.0, 20., 4., key=f"{k}_{i}")
109
+ elif k in ['attack_ms', 'release_ms']:
110
+ x = st.sidebar.slider(k, 0.1, 2000., key=f"{k}_{i}")
111
+ elif k in ['cutoff_frequency_hz', 'cutoff_hz', 'centre_frequency_hz']:
112
+ x = st.sidebar.slider(k, 20, 20000, key=f"{k}_{i}")
113
+ elif k in ['mode']:
114
+ choices = [LadderFilter.LPF12, LadderFilter.HPF12, LadderFilter.BPF12, LadderFilter.LPF24, LadderFilter.HPF24, LadderFilter.BPF24]
115
+ x = st.sidebar.selectbox(k, choices)
116
+ else:
117
+ x = type(v)(st.sidebar.text_input(k, value=v))
118
+ inputs[k] = x
119
+
120
+ # st.json(inputs)
121
+ transforms.append(obj(**inputs))
122
+ return transforms
123
+
124
+
125
+ # 🚨 TODO - messy. clean me pls.
126
+
127
+ audio_file = open('./download.wav', 'rb')
128
+ audio_bytes = audio_file.read()
129
+
130
+ st.markdown("## Input Audio")
131
+ st.audio(audio_bytes, format='audio/ogg')
132
+
133
+ # Run the audio through this pedalboard!
134
+ audio, sample_rate = sf.read('./download.wav')
135
+ board = Pedalboard(get_transforms(), sample_rate=sample_rate)
136
+ effected = board(audio)
137
+
138
+ # Write the audio back as a wav file:
139
+ with sf.SoundFile('./outputs.wav', 'w', samplerate=sample_rate, channels=len(effected.shape)) as f:
140
+ f.write(effected)
141
+
142
+
143
+ audio_file = open('./outputs.wav', 'rb')
144
+ audio_bytes = audio_file.read()
145
+
146
+ st.markdown("## Effected Audio")
147
+ st.audio(audio_bytes, format='audio/wav')
148
+
149
+
150
+ from matplotlib import pyplot as plt
151
+ import librosa
152
+ import librosa.display
153
+
154
+ fig = plt.figure(figsize=(14, 5))
155
+ librosa.display.waveplot(effected, sr=sample_rate)
156
+ st.pyplot(fig)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
1
+ streamlit==0.80.0
2
+ pedalboard