File size: 2,229 Bytes
8769669
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from __future__ import annotations

import gradio as gr

from pyharp import *


try:  # torch>=2.6 flipped torch.load(weights_only) to True; legacy ckpts need False
    import torch as _torch

    if getattr(_torch.load, "__harp_compat__", False) is False:
        _torch_load_orig = _torch.load

        def _torch_load_compat(*args, **kwargs):
            kwargs.setdefault("weights_only", False)
            return _torch_load_orig(*args, **kwargs)

        _torch_load_compat.__harp_compat__ = True
        _torch.load = _torch_load_compat
except Exception:  # torch not installed / unexpected API -- nothing to patch
    pass


import tempfile
import matchering as mg


model_card = ModelCard(
    name="Matchering",
    description="Match the RMS, Frequency Response, Peak Amplitude, and Stereo Width of a target track to a reference track for instant mastering.",
    author="sergree",
    tags=["audio", "mastering", "dsp", "matching"],
)


def process_fn(target_audio, ref_audio, bit_depth):
    out_file = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
    out_file.close()
    out_path = out_file.name

    if bit_depth == "pcm24":
        result_config = mg.pcm24(out_path)
    else:
        result_config = mg.pcm16(out_path)

    mg.process(
        target=target_audio,
        reference=ref_audio,
        results=[result_config]
    )

    return out_path


with gr.Blocks() as demo:
    input_components = [
        gr.Audio(type="filepath", label="Target Audio").harp_required(True).set_info("The track you want to master (your mix)."),
        gr.Audio(type="filepath", label="Reference Audio").harp_required(True).set_info("The reference track you want your target to sound like."),
        gr.Dropdown(choices=["pcm16", "pcm24"], value="pcm16", label="Output Bit Depth", info="Choose 16-bit PCM (CD quality) or 24-bit PCM (Studio quality) for the output file."),
    ]
    output_components = [
        gr.Audio(type="filepath", label="Mastered Audio"),
    ]
    build_endpoint(
        model_card=model_card,
        input_components=input_components,
        output_components=output_components,
        process_fn=process_fn,
    )

demo.queue().launch(share=True, show_error=False, pwa=True)