mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-10-03 00:55:14 -07:00
Enhance model download handling in useGenerationForm and ProgressManager
- Introduced a flag to track download status in useGenerationForm, ensuring proper UI updates during model downloads. - Updated ProgressManager to only send initial progress updates if the model is actively downloading or extracting, preventing outdated status messages from being sent. - Improved error handling and logging for better visibility into model download processes.
This commit is contained in:
@@ -70,6 +70,7 @@ export function useGenerationForm(options: UseGenerationFormOptions = {}) {
|
|||||||
const modelName = `qwen-tts-${data.modelSize}`;
|
const modelName = `qwen-tts-${data.modelSize}`;
|
||||||
const displayName = data.modelSize === '1.7B' ? 'Qwen TTS 1.7B' : 'Qwen TTS 0.6B';
|
const displayName = data.modelSize === '1.7B' ? 'Qwen TTS 1.7B' : 'Qwen TTS 0.6B';
|
||||||
|
|
||||||
|
let isDownloading = false;
|
||||||
try {
|
try {
|
||||||
const modelStatus = await apiClient.getModelStatus();
|
const modelStatus = await apiClient.getModelStatus();
|
||||||
const model = modelStatus.models.find((m) => m.model_name === modelName);
|
const model = modelStatus.models.find((m) => m.model_name === modelName);
|
||||||
@@ -77,6 +78,7 @@ export function useGenerationForm(options: UseGenerationFormOptions = {}) {
|
|||||||
if (model && !model.downloaded) {
|
if (model && !model.downloaded) {
|
||||||
setDownloadingModelName(modelName);
|
setDownloadingModelName(modelName);
|
||||||
setDownloadingDisplayName(displayName);
|
setDownloadingDisplayName(displayName);
|
||||||
|
isDownloading = true;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to check model status:', error);
|
console.error('Failed to check model status:', error);
|
||||||
@@ -101,16 +103,21 @@ export function useGenerationForm(options: UseGenerationFormOptions = {}) {
|
|||||||
|
|
||||||
form.reset();
|
form.reset();
|
||||||
options.onSuccess?.(result.id);
|
options.onSuccess?.(result.id);
|
||||||
|
|
||||||
|
if (isDownloading) {
|
||||||
|
setDownloadingModelName(null);
|
||||||
|
setDownloadingDisplayName(null);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
title: 'Generation failed',
|
title: 'Generation failed',
|
||||||
description: error instanceof Error ? error.message : 'Failed to generate audio',
|
description: error instanceof Error ? error.message : 'Failed to generate audio',
|
||||||
variant: 'destructive',
|
variant: 'destructive',
|
||||||
});
|
});
|
||||||
} finally {
|
|
||||||
setIsGenerating(false);
|
|
||||||
setDownloadingModelName(null);
|
setDownloadingModelName(null);
|
||||||
setDownloadingDisplayName(null);
|
setDownloadingDisplayName(null);
|
||||||
|
} finally {
|
||||||
|
setIsGenerating(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,10 +121,16 @@ class ProgressManager:
|
|||||||
logger.info(f"SSE client subscribed to {model_name}, total listeners: {len(self._listeners[model_name])}")
|
logger.info(f"SSE client subscribed to {model_name}, total listeners: {len(self._listeners[model_name])}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Send initial progress if available
|
# Send initial progress if available and still in progress
|
||||||
if model_name in self._progress:
|
if model_name in self._progress:
|
||||||
logger.info(f"Sending initial progress for {model_name}: {self._progress[model_name].get('status')}")
|
status = self._progress[model_name].get('status')
|
||||||
yield f"data: {json.dumps(self._progress[model_name])}\n\n"
|
# Only send initial progress if download is actually in progress
|
||||||
|
# Don't send old 'complete' or 'error' status from previous downloads
|
||||||
|
if status in ('downloading', 'extracting'):
|
||||||
|
logger.info(f"Sending initial progress for {model_name}: {status}")
|
||||||
|
yield f"data: {json.dumps(self._progress[model_name])}\n\n"
|
||||||
|
else:
|
||||||
|
logger.info(f"Skipping initial progress for {model_name} (status: {status})")
|
||||||
else:
|
else:
|
||||||
logger.info(f"No initial progress available for {model_name}")
|
logger.info(f"No initial progress available for {model_name}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user