Skip to content

Commit 0a9e218

Browse files
committed
improved rvc api
1 parent 5c3bf74 commit 0a9e218

File tree

6 files changed

+9
-27
lines changed

6 files changed

+9
-27
lines changed

Home.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121

2222
from webui.contexts import ProgressBarContext, SessionStateContext
2323

24-
def download_audio_to_buffer(url):
24+
@st.cache_data
25+
def download_audio_to_buffer(url,subtype="mp4"):
2526
buffer = BytesIO()
2627
youtube_video = YouTube(url)
27-
audio = youtube_video.streams.get_audio_only()
28+
audio = youtube_video.streams.get_audio_only(subtype=subtype)
2829
default_filename = slugify_filepath(audio.default_filename)
2930
audio.stream_to_buffer(buffer)
3031
return default_filename, buffer

api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ async def get_rvc():
2424
gc_collect()
2525
return list_rvc_models()
2626

27-
@server.post("/rvc")
28-
async def rvc_infer(body: RVCInferenceParams):
27+
@server.post("/rvc/{name}")
28+
async def rvc_infer(body: RVCInferenceParams, name: str):
2929
response = {}
3030
gc_collect()
31-
output_audio = convert_vocals(**vars(body))
31+
output_audio = convert_vocals(name=name,**vars(body))
3232
if output_audio: response["data"] = audio2bytes(*output_audio)
3333
gc_collect()
3434
return response

lib/audio.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,6 @@ def bytes_to_audio(data: Union[io.BytesIO,bytes],**kwargs):
9999
audio = audio.T # transpose to channels-first
100100
return audio, sr
101101

102-
# def bytes2audio(data: str):
103-
# try:
104-
# iofile = io.BytesIO(base64.b64decode(data))
105-
# decoded = np.load(iofile)
106-
# return decoded["audio"], decoded["sr"]+0
107-
# except Exception as e:
108-
# print(e)
109-
# return None
110-
111-
# def audio2bytes(audio: np.array, sr: int):
112-
# try:
113-
# iofile = io.BytesIO()
114-
# np.savez_compressed(iofile,audio=audio,sr=sr)
115-
# return base64.b64encode(iofile.getvalue()).decode("utf-8")
116-
# except Exception as e:
117-
# print(e)
118-
# return ""
119-
120102
def bytes2audio(data: str):
121103
try:
122104
# Split the suffixed data by the colon

lib/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_optimal_torch_device(index = 0) -> torch.device:
6868

6969
def get_optimal_threads(offset=0):
7070
cores = multiprocessing.cpu_count() - offset
71-
return max(np.floor(cores * (1-psutil.cpu_percent())),1)
71+
return int(max(np.floor(cores * (1-psutil.cpu_percent())),1))
7272

7373
def pid_is_active(pid: int):
7474
""" Check For the existence of a unix pid. https://stackoverflow.com/a/568285"""

server/types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44

55
class RVCInferenceParams(BaseModel):
6-
name: str
76
audio_data: str
87
f0_up_key: int=0
98
f0_method: List[Literal["rmvpe","rmvpe+","crepe","mangio-crepe"]]=["rmvpe"]

webui/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ def split_vocals(audio_path,**args):
6767
def convert_vocals(model_name,input_audio,**kwargs):
6868
gc_collect()
6969
audio_data = audio2bytes(*input_audio)
70-
body = dict(name=model_name,audio_data=audio_data,**kwargs)
70+
body = dict(audio_data=audio_data,**kwargs)
7171

72-
with requests.post(RVC_INFERENCE_URL,json=body) as req:
72+
with requests.post(f"{RVC_INFERENCE_URL}/{model_name}",json=body) as req:
7373
if req.status_code==200:
7474
response = req.json()
7575
audio = bytes2audio(response["data"])

0 commit comments

Comments
 (0)