AIGC-Audio / AudioGPT

AudioGPT: Understanding and Generating Speech, Music, Sound, and Talking Head
https://huggingface.co/spaces/AIGC-Audio/AudioGPT
Other
9.9k stars 846 forks source link

Refactor code for optimization and readability. #47

Open qw87rt opened 1 year ago

qw87rt commented 1 year ago

Unused imports: The numpy library is imported but not used anywhere in the code. It can be safely removed.

Redundant function definitions: The extract function is called by both extract_sentbert and extract_originbert functions. Instead of defining two separate functions for these two cases, you can define a single function that takes the model as a parameter.

Redundant code: The dev parameter is used to control whether to store the embeddings for each caption separately or concatenate them and store for each key. However, this parameter is only used in the extract function, and not in extract_sentbert or extract_originbert. Therefore, the dev parameter can be removed from both extract_sentbert and extract_originbert functions.

Progress bar: The tqdm library is used to display a progress bar for the loop that iterates over the caption data frame. However, the progress bar is not shown if dev=False in the extract function. To show a progress bar in both cases, you can move the tqdm initialization to the beginning of the extract function, and use it in both cases.