Update handler.py
Browse files- handler.py +8 -0
handler.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
from typing import Dict, List, Any
|
|
|
|
|
|
|
| 2 |
from transformers import AutoProcessor, MusicgenForConditionalGeneration
|
| 3 |
import torch
|
| 4 |
|
|
@@ -25,6 +27,12 @@ class EndpointHandler:
|
|
| 25 |
inputs = data.pop("inputs", data)
|
| 26 |
parameters = data.pop("parameters", None)
|
| 27 |
duration = parameters.pop("duration", None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
if duration is not None:
|
| 30 |
# Calculate max new tokens based on duration, this is a placeholder, replace with actual logic
|
|
|
|
| 1 |
from typing import Dict, List, Any
|
| 2 |
+
import json
|
| 3 |
+
import numpy as np
|
| 4 |
from transformers import AutoProcessor, MusicgenForConditionalGeneration
|
| 5 |
import torch
|
| 6 |
|
|
|
|
| 27 |
inputs = data.pop("inputs", data)
|
| 28 |
parameters = data.pop("parameters", None)
|
| 29 |
duration = parameters.pop("duration", None)
|
| 30 |
+
audio = parameters.pop("audio", None)
|
| 31 |
+
|
| 32 |
+
if audio is not None:
|
| 33 |
+
audio_list = json.loads(audio)
|
| 34 |
+
audio_array = np.array(audio_list)
|
| 35 |
+
parameters["audio"] = audio_array
|
| 36 |
|
| 37 |
if duration is not None:
|
| 38 |
# Calculate max new tokens based on duration, this is a placeholder, replace with actual logic
|