File size: 1,311 Bytes
a406960
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa1adc3
 
 
 
 
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
import gradio as gr
import matchering as mg
import tempfile
import os

from pyharp import ModelCard, build_endpoint

model_card = ModelCard(
    name="Matchering 2.0",
    description="Automatic audio mastering using a reference track.",
    author="Matchering",
    tags=["mastering", "audio", "production"]
)

def process_fn(target_path, reference_path):
    try:
        output_file = tempfile.NamedTemporaryFile(
            delete=False, suffix=".wav"
        ).name

        mg.process(
            target=target_path,
            reference=reference_path,
            results=[mg.pcm16(output_file)],
        )

        return output_file

    except Exception as e:
        print("Error:", e)
        return target_path

with gr.Blocks() as demo:
    input_target = gr.Audio(type="filepath", label="Target Track").harp_required(True)
    input_reference = gr.Audio(type="filepath", label="Reference Track").harp_required(True)

    output_audio = gr.Audio(type="filepath", label="Mastered Output")

    build_endpoint(
        model_card=model_card,
        process_fn=process_fn,
        input_components=[input_target, input_reference],
        output_components=[output_audio],
    )

if __name__ == "__main__":
    demo.queue().launch(
        server_name="0.0.0.0",
        server_port=7860
    )