Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop-gpui): skip a Whisper model that is still downloading in the caption fallback

Theophilus2003ddb278cbb87b
diff --git a/apps/desktop-gpui/src/transcription.rs b/apps/desktop-gpui/src/transcription.rs
index f89be16af..406d70b25 100644
--- a/apps/desktop-gpui/src/transcription.rs
+++ b/apps/desktop-gpui/src/transcription.rs
@@ -184,6 +184,12 @@ struct Hub {
}
impl Hub {
+ fn downloading(&self, model: &str) -> bool {
+ self.download.as_ref().is_some_and(|download| {
+ download.model == model && download.state == DownloadState::Downloading
+ })
+ }
+
fn work_in_flight(&self) -> bool {
self.download
.as_ref()
@@ -1765,7 +1771,11 @@ pub fn transcribe_blocking(
language: &str,
) -> Result<Vec<CaptionSegment>, String> {
let requested = model;
- let model = transcription_model(model, language, model_files_present)?;
+ // A download writes straight to the model's final path, so a model still
+ // downloading looks present but cannot load yet.
+ let model = transcription_model(model, language, |model| {
+ model_files_present(model) && !hub().downloading(model)
+ })?;
if model != requested {
tracing::info!("{requested} cannot transcribe {language}; using the {model} Whisper model");
}
@@ -2283,7 +2293,7 @@ pub fn caption_generation_error_message(message: &str) -> String {
return "Failed to load the caption model. Try downloading it again".to_string();
}
if message.contains(PARAKEET_UNSUPPORTED_LANGUAGE) {
- return "The Recommended and High Accuracy models only transcribe European languages. Download the Small or Medium model to caption this language".to_string();
+ return "The Recommended and High Accuracy models only transcribe English and 24 other European languages. Download the Small or Medium model to caption this language".to_string();
}
if message.contains("Parakeet transcription is not available on Intel macOS") {
return "Parakeet models are not available on Intel Macs. Use a Whisper model instead"
@@ -2321,6 +2331,10 @@ mod tests {
transcription_model("best-max", language, |model| model == "small"),
Ok("small")
);
+ assert_eq!(
+ transcription_model("best", language, |model| model != "medium"),
+ Ok("small")
+ );
let error = transcription_model("best", language, |_| false).unwrap_err();
assert!(caption_generation_error_message(&error).contains("Small or Medium"));
}
@@ -2548,6 +2562,22 @@ mod tests {
assert_eq!(model_path("medium"), base.join("medium.bin"));
}
+ #[test]
+ fn only_the_model_being_downloaded_counts_as_downloading() {
+ let mut state = Hub::default();
+ assert!(!state.downloading("medium"));
+ state.download = Some(ModelDownload {
+ model: "medium".to_string(),
+ state: DownloadState::Downloading,
+ progress: 40.0,
+ message: "Downloading".to_string(),
+ });
+ assert!(state.downloading("medium"));
+ assert!(!state.downloading("small"));
+ state.download.as_mut().unwrap().state = DownloadState::Completed;
+ assert!(!state.downloading("medium"));
+ }
+
#[test]
fn downloads_generation_and_deletion_block_application_handoffs() {
let mut state = Hub::default();