yoyolicoris commited on
Commit
78936ff
·
1 Parent(s): 2dc6a6a

Add model2json function to serialize effect settings as JSON

Browse files
Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -140,6 +140,29 @@ def get_important_pcs(n=10, **kwargs):
140
  return sliders
141
 
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  with gr.Blocks() as demo:
144
  gr.Markdown(
145
  title_md,
@@ -177,15 +200,16 @@ with gr.Blocks() as demo:
177
  audio_output = gr.Audio(
178
  type="numpy", label="Output Audio", interactive=False
179
  )
 
180
 
181
  render_button.click(
182
- inference,
183
  inputs=[
184
  audio_input,
185
  random_rest_checkbox,
186
  ]
187
  + sliders,
188
- outputs=audio_output,
189
  )
190
 
191
  random_button.click(
 
140
  return sliders
141
 
142
 
143
+ def model2json():
144
+ fx_names = ["PK1", "PK2", "LS", "HS", "LP", "HP", "DRC"]
145
+ results = {k: v.toJSON() for k, v in zip(fx_names, fx)} | {
146
+ "Panner": fx[7].pan.toJSON()
147
+ }
148
+ spatial_fx = {
149
+ "DLY": fx[7].effects[0].toJSON() | {"LP": fx[7].effects[0].eq.toJSON()},
150
+ "FDN": fx[7].effects[1].toJSON()
151
+ | {
152
+ "Tone correction PEQ": {
153
+ k: v.toJSON() for k, v in zip(fx_names[:4], fx[7].effects[1].eq)
154
+ }
155
+ },
156
+ "Cross Send (dB)": fx[7].params.sends_0.log10().mul(20).item(),
157
+ }
158
+ return json.dumps(
159
+ {
160
+ "Direct": results,
161
+ "Sends": spatial_fx,
162
+ }
163
+ )
164
+
165
+
166
  with gr.Blocks() as demo:
167
  gr.Markdown(
168
  title_md,
 
200
  audio_output = gr.Audio(
201
  type="numpy", label="Output Audio", interactive=False
202
  )
203
+ json_output = gr.JSON(label="Effect Settings", max_height=800, open=True)
204
 
205
  render_button.click(
206
+ lambda *args: (lambda x: (x, model2json()))(inference(*args)),
207
  inputs=[
208
  audio_input,
209
  random_rest_checkbox,
210
  ]
211
  + sliders,
212
+ outputs=[audio_output, json_output],
213
  )
214
 
215
  random_button.click(