-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
62 lines (47 loc) · 1.36 KB
/
app.py
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
from pyharp import *
import gradio as gr
import torchaudio
import torch
# Create a ModelCard
model_card = ModelCard(
name="Pitch Shifter",
description="A pitch shifting example for HARP.",
author="Hugo Flores Garcia",
tags=["example", "pitch shift"],
midi_in=False,
midi_out=False
)
# Define the process function
@torch.inference_mode()
def process_fn(input_audio_path, pitch_shift_amount):
if isinstance(pitch_shift_amount, torch.Tensor):
pitch_shift_amount = pitch_shift_amount.long().item()
sig = load_audio(input_audio_path)
ps = torchaudio.transforms.PitchShift(
sig.sample_rate,
n_steps=pitch_shift_amount,
bins_per_octave=12,
n_fft=512
)
sig.audio_data = ps(sig.audio_data)
output_audio_path = save_audio(sig)
# No output labels
output_labels = LabelList()
return output_audio_path, output_labels
# Build Gradio endpoint
with gr.Blocks() as demo:
# Define Gradio Components
components = [
gr.Slider(
minimum=-24,
maximum=24,
step=1,
value=7,
label="Pitch Shift (semitones)"
),
]
app = build_endpoint(model_card=model_card,
components=components,
process_fn=process_fn)
demo.queue()
demo.launch(share=True, show_error=True)