Skip to content

Commit

Permalink
fix ReactUI - MusicGen (#355)
Browse files Browse the repository at this point in the history
* add unload_models to whisper

* fix musicgen api for React UI
  • Loading branch information
rsxdalv authored Jul 31, 2024
1 parent 6ba936a commit d80f738
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ List of models: Bark, MusicGen + AudioGen, Tortoise, RVC, Vocos, Demucs, Seamles

## Changelog

July 31:
* Fix React UI's MusicGen after the Gradio changes.
* Add unload button to Whisper extension.

July 29:
* Change FFMpeg to 4.4.2 from conda-forge in order to support more platforms, including Mac M1.
* Disable tortoise CVVP.
Expand Down
27 changes: 23 additions & 4 deletions extensions/builtin/extension_whisper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ def extension__tts_generation_webui():
last_model_name = None


def unload_models():
global pipe, last_model_name
pipe = None
last_model_name = None
gc.collect()
if torch.cuda.is_available():
torch.cuda.empty_cache()
return "Unloaded"


def get_pipe(model_name, device="cuda:0") -> Pipeline:
global pipe, last_model_name
if pipe is not None:
if model_name == last_model_name:
return pipe
gc.collect()
torch.cuda.empty_cache()
unload_models()
pipe = pipeline(
"automatic-speech-recognition",
model_name,
Expand Down Expand Up @@ -98,14 +107,24 @@ def transcribe_ui():
text = gr.Textbox(label="Transcription", interactive=False)

with gr.Row():
with gr.Column():
transcribe_button = gr.Button("Transcribe", variant="primary")
unload_models_button = gr.Button("Unload models")

transcribe_button = gr.Button("Transcribe", variant="primary")

transcribe_button.click(
fn=transcribe,
inputs=[audio, model_dropdown],
outputs=[text],
api_name="whisper_transcribe",
).then(
fn=lambda: gr.Button.update(value="Unload models"),
outputs=[unload_models_button],
)

unload_models_button.click(
fn=unload_models,
outputs=[unload_models_button],
api_name="whisper_unload_models",
)


Expand Down
13 changes: 9 additions & 4 deletions react-ui/src/pages/api/gradio/[name].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ async function musicgen({ melody, ...params }) {
Object // result_json
]
>("/musicgen", [
{
melody: null,
...params,
},
params.text,
melodyBlob, // blob in 'Melody (optional)' Audio component
params.model, // string (Option from: ['facebook/musicgen-small', 'facebook/musicgen-medium', 'facebook/musicgen-large', 'facebook/musicgen-large-v2', 'facebook/musicgen-large-v2-melody']) in 'Model'
params.duration, // number in 'Duration' Slider component
params.topk, // number in 'Top K' Slider component
params.topp, // number in 'Top P' Slider component
params.temperature, // number in 'Temperature' Slider component
params.cfg_coef, // number in 'CFG Coefficient' Slider component
params.seed, // number in 'Seed' Slider component
params.use_multi_band_diffusion, // boolean in 'Use Multi-Band Diffusion' Checkbox component
]);
const [audio, history_bundle_name_data, , , json] = result?.data;
return {
Expand Down

0 comments on commit d80f738

Please sign in to comment.