File size: 880 Bytes
0a56a24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""HuggingFace Inference Endpoint handler for the DAM model."""

import io
from pathlib import Path

from pipeline import Pipeline


class EndpointHandler:
    def __init__(self, path=""):
        checkpoint = Path(path) / "dam3.1.ckpt"
        self.pipeline = Pipeline(checkpoint=checkpoint)

    def __call__(self, data):
        inputs = data.get("inputs")
        if isinstance(inputs, bytes):
            source = io.BytesIO(inputs)
        else:
            raise ValueError("Expected raw audio bytes in data['inputs']")

        quantized = self.pipeline.run_on_file(source, quantize=True)
        source.seek(0)
        raw = self.pipeline.run_on_file(source, quantize=False)

        return {
            "depression": quantized["depression"],
            "anxiety": quantized["anxiety"],
            "raw_scores": {k: v.mean().item() for k, v in raw.items()},
        }