mod config;
#[cfg(any(
feature = "candle-trocr",
feature = "candle-paddleocr-vl",
all(
not(target_arch = "wasm32"),
any(feature = "candle-glm-ocr", feature = "candle-deepseek-ocr")
)
))]
mod ocr_result;
#[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::{
CandleDevicePreference, CandleModelId, CandleOcrConfig, CandleTrocrVariant, DeepseekOcrBackendOptions,
GlmOcrBackendOptions, GlmOcrLayoutMode, GlmOcrTaskKind, PaddleOcrVlBackendOptions, PaddleOcrVlTaskKind,
TrocrBackendOptions,
};
#[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,
explicit: Option<CandleDevicePreference>,
) -> DevicePreference {
if let Some(explicit) = explicit {
return explicit.into();
}
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,
}
}