#[cfg(feature = "gui")]
mod controller;
mod engine;
#[cfg(feature = "gui")]
pub use controller::OcrFeature;
pub use engine::{OcrEngine, OcrResult, TrOCRModel};
pub use crate::ml::{
DownloadProgress, DownloadStatus, ModelInfo, ModelManager, ModelType,
get_ml_data_dir as get_ocr_data_dir, get_models_dir, get_trocr_models_dir,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum OcrModelVariant {
BaseHandwritten,
#[default]
BasePrinted,
LargeHandwritten,
LargePrinted,
}
impl OcrModelVariant {
pub fn model_id(&self) -> &'static str {
match self {
Self::BaseHandwritten => "trocr-base-handwritten",
Self::BasePrinted => "trocr-base-printed",
Self::LargeHandwritten => "trocr-large-handwritten",
Self::LargePrinted => "trocr-large-printed",
}
}
pub fn repo_id(&self) -> &'static str {
match self {
Self::BaseHandwritten => "microsoft/trocr-base-handwritten",
Self::BasePrinted => "microsoft/trocr-base-printed",
Self::LargeHandwritten => "microsoft/trocr-large-handwritten",
Self::LargePrinted => "microsoft/trocr-large-printed",
}
}
pub fn name(&self) -> &'static str {
match self {
Self::BaseHandwritten => "TrOCR Base Handwritten",
Self::BasePrinted => "TrOCR Base Printed",
Self::LargeHandwritten => "TrOCR Large Handwritten",
Self::LargePrinted => "TrOCR Large Printed",
}
}
pub fn display_name(&self) -> &'static str {
match self {
Self::BaseHandwritten => "Base Handwritten",
Self::BasePrinted => "Base Printed",
Self::LargeHandwritten => "Large Handwritten",
Self::LargePrinted => "Large Printed",
}
}
pub fn description(&self) -> &'static str {
match self {
Self::BaseHandwritten => "Optimized for handwritten text",
Self::BasePrinted => "Optimized for printed/digital text",
Self::LargeHandwritten => "Higher accuracy for handwritten text",
Self::LargePrinted => "Higher accuracy for printed text",
}
}
pub fn all() -> &'static [Self] {
&[Self::BaseHandwritten, Self::BasePrinted, Self::LargeHandwritten, Self::LargePrinted]
}
pub fn from_model_id(id: &str) -> Option<Self> {
match id {
"trocr-base-handwritten" => Some(Self::BaseHandwritten),
"trocr-base-printed" => Some(Self::BasePrinted),
"trocr-large-handwritten" => Some(Self::LargeHandwritten),
"trocr-large-printed" => Some(Self::LargePrinted),
_ => None,
}
}
}