mod config;
#[cfg(feature = "candle-trocr")]
pub mod trocr_backend;
#[cfg(feature = "candle-paddleocr-vl")]
pub mod paddleocr_vl_backend;
#[cfg(all(feature = "candle-glm-ocr", not(target_arch = "wasm32")))]
pub mod glm_ocr_backend;
#[cfg(feature = "candle-paddleocr-vl")]
pub(crate) mod model_stager;
#[cfg(all(feature = "candle-deepseek-ocr", not(target_arch = "wasm32")))]
pub mod deepseek_ocr_backend;
pub use config::{CandleModelId, CandleOcrConfig};
#[cfg(feature = "candle-trocr")]
pub use trocr_backend::TrocrBackend;
#[cfg(feature = "candle-paddleocr-vl")]
pub use paddleocr_vl_backend::PaddleOcrVlBackend;
#[cfg(all(feature = "candle-glm-ocr", not(target_arch = "wasm32")))]
pub use glm_ocr_backend::GlmOcrBackend;
#[cfg(all(feature = "candle-deepseek-ocr", not(target_arch = "wasm32")))]
pub use deepseek_ocr_backend::DeepseekOcrBackend;
#[cfg(any(
feature = "candle-trocr",
feature = "candle-paddleocr-vl",
all(
not(target_arch = "wasm32"),
any(feature = "candle-glm-ocr", feature = "candle-deepseek-ocr")
)
))]
use crate::core::config::{AccelerationConfig, ExecutionProviderType, OcrConfig};
#[cfg(any(
feature = "candle-trocr",
feature = "candle-paddleocr-vl",
all(
not(target_arch = "wasm32"),
any(feature = "candle-glm-ocr", feature = "candle-deepseek-ocr")
)
))]
use xberg_candle_ocr::DevicePreference;
#[cfg(any(
feature = "candle-trocr",
feature = "candle-paddleocr-vl",
all(
not(target_arch = "wasm32"),
any(feature = "candle-glm-ocr", feature = "candle-deepseek-ocr")
)
))]
pub(crate) fn resolve_device_preference(config: &OcrConfig) -> DevicePreference {
if let Some(opts) = &config.backend_options
&& let Some(v) = opts.get("device").and_then(|v| v.as_str())
{
match v {
"cpu" => return DevicePreference::Cpu,
"cuda" => return DevicePreference::Cuda,
"metal" => return DevicePreference::Metal,
"auto" => return DevicePreference::Auto,
_ => {}
}
}
if let Some(accel) = &config.acceleration {
return device_preference_from_acceleration(accel);
}
DevicePreference::Auto
}
#[cfg(any(
feature = "candle-trocr",
feature = "candle-paddleocr-vl",
all(
not(target_arch = "wasm32"),
any(feature = "candle-glm-ocr", feature = "candle-deepseek-ocr")
)
))]
fn device_preference_from_acceleration(accel: &AccelerationConfig) -> DevicePreference {
match accel.provider {
ExecutionProviderType::Auto => DevicePreference::Auto,
ExecutionProviderType::Cpu => DevicePreference::Cpu,
ExecutionProviderType::Cuda | ExecutionProviderType::TensorRt => DevicePreference::Cuda,
ExecutionProviderType::CoreMl => DevicePreference::Metal,
}
}