Commit ·
1dd3b95
1
Parent(s): 0b5d8bf
Update handler.py
Browse files- handler.py +7 -3
handler.py
CHANGED
|
@@ -17,7 +17,11 @@ class EndpointHandler:
|
|
| 17 |
# process input
|
| 18 |
inputs = data.pop("inputs", data)
|
| 19 |
parameters = data.pop("parameters", None)
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# preprocess
|
| 22 |
inputs = self.processor(
|
| 23 |
text=[inputs],
|
|
@@ -26,9 +30,9 @@ class EndpointHandler:
|
|
| 26 |
|
| 27 |
# pass inputs with all kwargs in data
|
| 28 |
if parameters is not None:
|
| 29 |
-
outputs = self.model.generate(**inputs, max_new_tokens=
|
| 30 |
else:
|
| 31 |
-
outputs = self.model.generate(**inputs, max_new_tokens=
|
| 32 |
|
| 33 |
# postprocess the prediction
|
| 34 |
prediction = outputs[0].cpu().numpy()
|
|
|
|
| 17 |
# process input
|
| 18 |
inputs = data.pop("inputs", data)
|
| 19 |
parameters = data.pop("parameters", None)
|
| 20 |
+
|
| 21 |
+
duration = data.pop("duration", 5.0)
|
| 22 |
+
duration = max(min(duration, 30.0), 0.0)
|
| 23 |
+
max_new_tokens = int(duration * self.model.config.audio_encoder.frame_rate)
|
| 24 |
+
|
| 25 |
# preprocess
|
| 26 |
inputs = self.processor(
|
| 27 |
text=[inputs],
|
|
|
|
| 30 |
|
| 31 |
# pass inputs with all kwargs in data
|
| 32 |
if parameters is not None:
|
| 33 |
+
outputs = self.model.generate(**inputs, max_new_tokens=max_new_tokens, **parameters)
|
| 34 |
else:
|
| 35 |
+
outputs = self.model.generate(**inputs, max_new_tokens=max_new_tokens)
|
| 36 |
|
| 37 |
# postprocess the prediction
|
| 38 |
prediction = outputs[0].cpu().numpy()
|