-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a REST api service with fastapi for simple inferencing. #1614
base: dev
Are you sure you want to change the base?
Conversation
… to accept also byte arrays
… to accept also byte arrays
…ds compatibility in tests
This significantly speeds up the inference process compared to the currently available API. |
I agree with you. Need @RVC-Boss to decide whether merge or not. |
this would be a great addition - please @RVC-Boss can you help merging? |
Hi, I have cloned this solution to test it out but I am not able to successfully process using the api. No matter what I put as the value for input_path or input_file, I am getting "detail": "infer() missing 1 required positional argument: 'input'" or {"detail":[{"loc":["body","input_file"],"msg":"field required","type":"value_error.missing"}]}. I've tried both the endpoints local and non local. |
Hey, I already made some changes there to improve and added also pure rest inference points without local paths, what works even better. I did not know how ho update the pull request with git though |
The last changes I see are dated three weeks ago. Did you make any other changes? |
@w4hns1nn maybe you can create a new PR? |
or
|
Just edit your fork https://github.com/w4hns1nn/Retrieval-based-Voice-Conversion-FastAPI/tree/main and it will update to this PR automatically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please also add a response_format
param?
|
||
# call the infer function | ||
try: | ||
wf = infer(**kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a response_format
parameter here to decide whether to response in wav or mp3 format?
Like this:
def infer(
input: Union[str, bytes], # filepath or raw bytes
model_name: str,
response_format: str = 'wav', # new parameter for specifying the output format
index_path: str = None,
f0up_key: int = 0,
f0method: str = "crepe",
index_rate: float = 0.66,
device: str = None,
is_half: bool = False,
filter_radius: int = 3,
resample_sr: int = 0,
rms_mix_rate: float = 1,
protect: float = 0.33,
**kwargs
):
if response_format.lower() not in ['wav', 'mp3', 'flac', 'ogg', 'aac']:
raise ValueError(f"Unsupported response_format: {response_format}. Supported formats: wav, mp3, flac, ogg, aac")
model_name = model_name.replace(".pth", "")
if index_path is None:
index_path = os.path.join("logs", model_name, f"added_IVF1254_Flat_nprobe_1_{model_name}_v2.index")
if not os.path.exists(index_path):
index_path = None
# raise ValueError(f"autinferred index_path {index_path} does not exist. Please provide a valid index_path")
vc = model_cache.load_model(model_name, device=device, is_half=is_half)
_, wav_opt = vc.vc_single(
sid=0,
input_audio_path=input,
f0_up_key=f0up_key,
f0_file=None,
f0_method=f0method,
file_index=index_path,
file_index2=None,
index_rate=index_rate,
filter_radius=filter_radius,
resample_sr=resample_sr,
rms_mix_rate=rms_mix_rate,
protect=protect
)
# using virtual file to be able to return it as response
wf = BytesIO()
# Check if the desired response format is valid and supported
# Save the output in the desired format
sf.write(wf, wav_opt[1], wav_opt[0], format=response_format.upper())
# Make sure to seek the beginning of the BytesIO object before returning it
wf.seek(0)
return wf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is from OpenAI TTS API, which allows user to decide response format
if index_path is None: | ||
index_path = os.path.join("logs", model_name, f"added_IVF1254_Flat_nprobe_1_{model_name}_v2.index") | ||
if not os.path.exists(index_path): | ||
raise ValueError(f"autinferred index_path {index_path} does not exist. Please provide a valid index_path") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some models do not come with index files. If fails to find index_path
, how about leaving it to None
instead of raising an Exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current version works without an index file just fine, just set "index_path": "None"
I will do, in a few weeks |
API is under development in this repository. |
Sorry, I'm new to using git. REST api service with fastapi This function has not been merged into the main or dev branch at present, right? Because I have not seen the existence of the rvc_fastapi.py file on main or dev. |
Yes, it is closed by a mistake. I will re-open it. |
Today I performed a request test on the function of this code and it works normally.
|
It’s baffling to me that this hasn’t been merged into the main branch after all this time. Without this API, RVC is literally unusable for my use case, and I doubt I’m the only one. |
i was playing with this branch, it was useful, but didn't u take in consideration concurrency, how we can deal with multiple requests, if u have multiple simultaneous requests will significally slow down inference time, can we do something like batching...? |
PR type
Description
Added a REST service with fastapi. By starting the server with "python rvc_fastapy.py" the REST service is launched under localhost:8080. The API is well documented and easy to use.
Screenshot