mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-16 13:20:39 -07:00
Refactor useGenerationForm to streamline model download handling
- Removed unnecessary isDownloading variable and related logic. - Consolidated model download state reset to the finally block for improved clarity and reliability. - Enhanced error handling by ensuring model download state is reset in case of failure.
This commit is contained in:
@@ -70,7 +70,6 @@ export function useGenerationForm(options: UseGenerationFormOptions = {}) {
|
||||
const modelName = `qwen-tts-${data.modelSize}`;
|
||||
const displayName = data.modelSize === '1.7B' ? 'Qwen TTS 1.7B' : 'Qwen TTS 0.6B';
|
||||
|
||||
let isDownloading = false;
|
||||
try {
|
||||
const modelStatus = await apiClient.getModelStatus();
|
||||
const model = modelStatus.models.find((m) => m.model_name === modelName);
|
||||
@@ -78,7 +77,6 @@ export function useGenerationForm(options: UseGenerationFormOptions = {}) {
|
||||
if (model && !model.downloaded) {
|
||||
setDownloadingModelName(modelName);
|
||||
setDownloadingDisplayName(displayName);
|
||||
isDownloading = true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to check model status:', error);
|
||||
@@ -103,21 +101,16 @@ export function useGenerationForm(options: UseGenerationFormOptions = {}) {
|
||||
|
||||
form.reset();
|
||||
options.onSuccess?.(result.id);
|
||||
|
||||
if (isDownloading) {
|
||||
setDownloadingModelName(null);
|
||||
setDownloadingDisplayName(null);
|
||||
}
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: 'Generation failed',
|
||||
description: error instanceof Error ? error.message : 'Failed to generate audio',
|
||||
variant: 'destructive',
|
||||
});
|
||||
setDownloadingModelName(null);
|
||||
setDownloadingDisplayName(null);
|
||||
} finally {
|
||||
setIsGenerating(false);
|
||||
setDownloadingModelName(null);
|
||||
setDownloadingDisplayName(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user