Update ocrs models to S3 endpoints and add download error logging

This commit is contained in:
Riz Ashraf committed 2026-10-08 22:38:38 +01:00
1 parent 5c5aead1a5
commit 7eae2fa0aa
1 file changed
+18 -4
+18 -4
View File
@@ -304,19 +304,33 @@ pub async fn ensure_ocr_engine() -> Option<&'static OcrEngine> {
let det_path = cache_dir.join("text-detection.rten"); let det_path = cache_dir.join("text-detection.rten");
if !det_path.exists() || std::fs::metadata(&det_path).map(|m| m.len()).unwrap_or(0) < 100_000 { if !det_path.exists() || std::fs::metadata(&det_path).map(|m| m.len()).unwrap_or(0) < 100_000 {
if let Ok(resp) = reqwest::get("https://huggingface.co/robertknight/ocrs/resolve/main/text-detection.rten").await { match reqwest::get("https://ocrs-models.s3-accelerate.amazonaws.com/text-detection.rten").await {
Ok(resp) => {
if let Ok(bytes) = resp.bytes().await { if let Ok(bytes) = resp.bytes().await {
let _ = std::fs::write(&det_path, bytes); if let Err(e) = std::fs::write(&det_path, &bytes) {
tracing::error!("Failed to write text-detection.rten to disk: {}", e);
} }
} else {
tracing::error!("Failed to read bytes from text-detection.rten download response");
}
},
Err(e) => tracing::error!("Failed to download text-detection.rten: {}", e),
} }
} }
let rec_path = cache_dir.join("text-recognition.rten"); let rec_path = cache_dir.join("text-recognition.rten");
if !rec_path.exists() || std::fs::metadata(&rec_path).map(|m| m.len()).unwrap_or(0) < 100_000 { if !rec_path.exists() || std::fs::metadata(&rec_path).map(|m| m.len()).unwrap_or(0) < 100_000 {
if let Ok(resp) = reqwest::get("https://huggingface.co/robertknight/ocrs/resolve/main/text-recognition.rten").await { match reqwest::get("https://ocrs-models.s3-accelerate.amazonaws.com/text-recognition.rten").await {
Ok(resp) => {
if let Ok(bytes) = resp.bytes().await { if let Ok(bytes) = resp.bytes().await {
let _ = std::fs::write(&rec_path, bytes); if let Err(e) = std::fs::write(&rec_path, &bytes) {
tracing::error!("Failed to write text-recognition.rten to disk: {}", e);
} }
} else {
tracing::error!("Failed to read bytes from text-recognition.rten download response");
}
},
Err(e) => tracing::error!("Failed to download text-recognition.rten: {}", e),
} }
} }