Andrew commited on
Commit
5bc2ec0
·
1 Parent(s): 21c11ec

model inferencing

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. handler.py +26 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
handler.py CHANGED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64, io
2
+ import numpy as np
3
+ import soundfile as sf
4
+
5
+ class EndpointHandler:
6
+ def __init__(self, path=""):
7
+ # Later: load ACE-Step pipeline/model here once.
8
+ self.ready = True
9
+
10
+ def __call__(self, data):
11
+ inputs = data.get("inputs", data)
12
+ duration = int(inputs.get("duration_sec", 6))
13
+ sr = int(inputs.get("sample_rate", 44100))
14
+ seed = int(inputs.get("seed", 42))
15
+
16
+ rng = np.random.default_rng(seed)
17
+ t = np.linspace(0, duration, int(sr * duration), endpoint=False)
18
+ audio = (0.07*np.sin(2*np.pi*440*t) + 0.01*rng.standard_normal(len(t))).astype(np.float32)
19
+
20
+ buf = io.BytesIO()
21
+ sf.write(buf, audio, sr, format="WAV")
22
+ return {
23
+ "audio_base64_wav": base64.b64encode(buf.getvalue()).decode("utf-8"),
24
+ "sample_rate": sr,
25
+ "duration_sec": duration
26
+ }