Update ocrs models to S3 endpoints and add download error logging
This commit is contained in:
1 parent
5c5aead1a5
commit
7eae2fa0aa
1 file changed
+22
-8
@@ -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 {
|
||||||
if let Ok(bytes) = resp.bytes().await {
|
Ok(resp) => {
|
||||||
let _ = std::fs::write(&det_path, bytes);
|
if let Ok(bytes) = resp.bytes().await {
|
||||||
}
|
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 {
|
||||||
if let Ok(bytes) = resp.bytes().await {
|
Ok(resp) => {
|
||||||
let _ = std::fs::write(&rec_path, bytes);
|
if let Ok(bytes) = resp.bytes().await {
|
||||||
}
|
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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user