Spaces:
Runtime error
Runtime error
File size: 1,907 Bytes
73baeae |
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 |
import os
from typing import Tuple
import gradio as gr
import numpy as np
import torch
from transformers import AutoProcessor
from inference import EnClap
def input_toggle(choice: str):
if choice == "file":
return gr.update(visible=True), gr.update(visible=False)
return gr.update(visible=False), gr.update(visible=True)
if __name__ == "__main__":
import logging
logging.getLogger().setLevel(logging.INFO)
ckpt_path = "./ckpt" # os.getenv("ckpt_path")
device = "cpu" # os.getenv("device")
enclap = EnClap(ckpt_path=ckpt_path, device=device)
def run_enclap(
input_type: str,
file_input: Tuple[int, np.ndarray],
mic_input: Tuple[int, np.ndarray],
seed: int,
) -> str:
print(input_type, file_input, mic_input)
input = file_input if input_type == "file" else mic_input
if input is None:
raise gr.Error("Input audio was not provided.")
res, audio = input
torch.manual_seed(seed)
return enclap.infer_from_audio(torch.from_numpy(audio), res)[0]
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
radio = gr.Radio(
["file", "mic"],
value="file",
label="Choose the input method of the audio.",
)
file = gr.Audio(label="Input", visible=True)
mic = gr.Mic(label="Input", visible=False)
slider = gr.Slider(minimum=0, maximum=100, label="Seed")
radio.change(fn=input_toggle, inputs=radio, outputs=[file, mic])
button = gr.Button("Run", label="run")
with gr.Column():
output = gr.Text(label="Output")
button.click(
fn=run_enclap, inputs=[radio, file, mic, slider], outputs=output
)
demo.launch()
|