Spaces:
Running
Running
feat(ocr): integrate dedicated Vietnamese PP-OCRv5 model and streamline dropdown
Browse filesFiles changed (7)
- .gitattributes+1
- ocr-studio/app.py+35-9
- ocr-studio/data/output/rec_vietnamese_infer/inference.jsonAdded
- ocr-studio/data/output/rec_vietnamese_infer/inference.pdiparamsAdded+3
- ocr-studio/data/output/rec_vietnamese_infer/inference.ymlAdded+267
- ocr-studio/data/vietnamese_dict.txtAdded+224
- ocr-studio/index.html+6-12
323 unmodified lines324325326327323 unmodified linesocr-studio/data/output/rec_cham_inference_v24/inference.pdiparams.info filter=lfs diff=lfs merge=lfs -text
ocr-studio/data/output/ch_PP-OCRv4_det_cham_infer/inference.pdiparams filter=lfs diff=lfs merge=lfs -text
ocr-studio/data/output/rec_vietnamese_infer/inference.pdiparams filter=lfs diff=lfs merge=lfs -text193 unmodified lines1941951961971971981992008 unmodified lines209210211212213214215216217218219220221222223224225226227228229230231232233234235236237212213214215216217218219238239240241242243244245246247248193 unmodified lines if version in ocr_models:
return ocr_models[version]
if version in ['vi', 'en', 'fr', 'japan']:
if version in ['en', 'fr', 'japan']:
ocr_model = OfficialPaddleOCRWrapper(lang=version)
ocr_models[version] = ocr_model
return ocr_model8 unmodified lines from tools.infer.predict_rec import TextRecognizer
import tools.infer.utility as utility
if version == 'vi':
model_dir = os.path.join(PROJECT_ROOT, "data", "output", "rec_vietnamese_infer")
dict_path = os.path.join(PROJECT_ROOT, "data", "vietnamese_dict.txt")
model_ready = os.path.exists(os.path.join(model_dir, "inference.pdiparams")) and os.path.exists(dict_path)
if not model_ready:
try:
print(f"📥 Downloading dedicated Vietnamese OCR model to {model_dir}...")
os.makedirs(model_dir, exist_ok=True)
import urllib.request
base_url = "https://huggingface.co/anbeo2004/paddleocr-v5-rec-vi-custom/resolve/main/"
dl_files = {
"custom_dict.txt": dict_path,
"inference.json": os.path.join(model_dir, "inference.json"),
"inference.yml": os.path.join(model_dir, "inference.yml"),
"inference.pdiparams": os.path.join(model_dir, "inference.pdiparams")
}
for fname, ftarget in dl_files.items():
if not os.path.exists(ftarget):
urllib.request.urlretrieve(base_url + fname, ftarget)
print("✅ Downloaded Vietnamese OCR model successfully.")
except Exception as e:
print(f"⚠️ Failed to auto-download Vietnamese model: {e}")
ocr_model = OfficialPaddleOCRWrapper(lang='vi')
ocr_models[version] = ocr_model
return ocr_model
else:
model_dir = os.path.join(PROJECT_ROOT, "data", "output", f"rec_cham_inference_{version}")
dict_path = os.path.join(PROJECT_ROOT, "data", f"cham_dict_{version}.txt")
if not os.path.exists(model_dir):
# Fallback to Golden Baseline v23 if version-specific folder is missing
model_dir = os.path.join(PROJECT_ROOT, "data", "output", "rec_cham_inference_v23")
if not os.path.exists(dict_path):
dict_path = os.path.join(PROJECT_ROOT, "data", "cham_dict_v23.txt")
model_dir = os.path.join(PROJECT_ROOT, "data", "output", f"rec_cham_inference_{version}")
dict_path = os.path.join(PROJECT_ROOT, "data", f"cham_dict_{version}.txt")
if not os.path.exists(model_dir):
# Fallback to Golden Baseline v23 if version-specific folder is missing
model_dir = os.path.join(PROJECT_ROOT, "data", "output", "rec_cham_inference_v23")
if not os.path.exists(dict_path):
dict_path = os.path.join(PROJECT_ROOT, "data", "cham_dict_v23.txt")
sys_argv_backup = sys.argv
sys.argv = [sys.argv[0]]123version https://git-lfs.github.com/spec/v1oid sha256:eb929c47e349f528c6ff7e00d67b101bf7bb7654dffb5d18ac4156550841ebd3size 75601159123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267Global: model_name: PP-OCRv5_server_recHpi: backend_configs: paddle_infer: trt_dynamic_shapes: &id001 x: - - 1 - 3 - 48 - 160 - - 1 - 3 - 48 - 320 - - 8 - 3 - 48 - 3200 tensorrt: dynamic_shapes: *id001PreProcess: transform_ops: - DecodeImage: channel_first: false img_mode: BGR - MultiLabelEncode: gtc_encode: NRTRLabelEncode - RecResizeImg: image_shape: - 3 - 48 - 512 - KeepKeys: keep_keys: - image - label_ctc - label_gtc - length - valid_ratioPostProcess: name: CTCLabelDecode character_dict: - '!' - '"' - '%' - '&' - '''' - ( - ) - ',' - '-' - . - / - '0' - '1' - '2' - '3' - '4' - '5' - '6' - '7' - '8' - '9' - ':' - ; - '?' - A - B - C - D - E - F - G - H - I - J - K - L - M - N - O - P - Q - R - S - T - U - V - W - X - Y - Z - '[' - ']' - _ - a - b - c - d - e - f - g - h - i - j - k - l - m - n - o - p - q - r - s - t - u - v - w - x - y - z - ² - À - Á - È - É - Ê - Ì - Í - Ð - Ò - Ó - Ô - Õ - Ö - Ù - Ú - Ü - Ý - à - á - â - ã - è - é - ê - ì - í - ð - ò - ó - ô - õ - ö - ù - ú - ü - ý - Ā - ā - Ă - ă - Đ - đ - Ĩ - ĩ - Ō - ō - Ũ - ũ - Ū - ū - Ơ - ơ - Ư - ư - Ạ - ạ - Ả - ả - Ấ - ấ - Ầ - ầ - Ẩ - ẩ - Ẫ - ẫ - Ậ - ậ - Ắ - ắ - Ằ - ằ - Ẳ - ẳ - Ẵ - ẵ - Ặ - ặ - Ẹ - ẹ - Ẻ - ẻ - Ẽ - ẽ - Ế - ế - Ề - ề - Ể - ể - Ễ - ễ - Ệ - ệ - Ỉ - ỉ - Ị - ị - Ọ - ọ - Ỏ - ỏ - Ố - ố - Ồ - ồ - Ổ - ổ - Ỗ - ỗ - Ộ - ộ - Ớ - ớ - Ờ - ờ - Ở - ở - Ỡ - ỡ - Ợ - ợ - Ụ - ụ - Ủ - ủ - Ứ - ứ - Ừ - ừ - Ử - ử - Ữ - ữ - Ự - ự - Ỳ - ỳ - Ỵ - ỵ - Ỷ - ỷ - Ỹ - ỹ123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224!"%&'(),-./0123456789:;?ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz²ÀÁÈÉÊÌÍÐÒÓÔÕÖÙÚÜÝàáâãèéêìíðòóôõöùúüýĀāĂăĐđĨĩŌōŨũŪūƠơƯưẠạẢảẤấẦầẨẩẪẫẬậẮắẰằẲẳẴẵẶặẸẹẺẻẼẽẾếỀềỂểỄễỆệỈỉỊịỌọỎỏỐốỒồỔổỖỗỘộỚớỜờỞởỠỡỢợỤụỦủỨứỪừỬửỮữỰựỲỳỴỵỶỷỸỹ1253 unmodified lines12541255125612571258125912601257125812591260126212631264126512661267126812691261126212631264126512661253 unmodified lines <div class="model-picker-wrap" title="Select neural OCR recognition architecture">
<span class="model-picker-label">Model:</span>
<select id="model-select" class="model-select-compact" onchange="updateModelBadge()">
<optgroup label="Paleographic Cham Models (Custom Fine-Tuned)">
<option value="v24" selected>Version 24 (Validated Baseline — Verse-Numeral & Noise-Resilient SVTR)</option>
<option value="v23">Version 23 (Golden Baseline — Visual Order SVTR)</option>
<option value="v22">Version 22 (Legacy Fallback Baseline)</option>
<optgroup label="Paleographic Cham Models">
<option value="v24" selected>Cham V24 (Recommended — Logical Order)</option>
<option value="v23">Cham V23 (Visual Order Baseline)</option>
</optgroup>
<optgroup label="Multilingual Baselines (PaddleOCR PP-OCRv4)">
<option value="vi">Vietnamese (Latin)</option>
<option value="en">English (Latin)</option>
<option value="fr">French (Latin)</option>
<option value="japan">Japanese (CJK)</option>
</optgroup>
<optgroup label="Autonomous Routing">
<option value="auto">Adaptive Dual-Engine (Cham & Vietnamese)</option>
<optgroup label="Bilingual & Modern Text">
<option value="auto">Auto Dual-Engine (Cham & Vietnamese)</option>
<option value="vi">Vietnamese (Fine-Tuned PP-OCRv5)</option>
</optgroup>
</select>
</div>.gitattributes+1
ocr-studio/app.py+35-9
ocr-studio/data/output/rec_vietnamese_infer/inference.jsonAdded
ocr-studio/data/output/rec_vietnamese_infer/inference.pdiparamsAdded+3
ocr-studio/data/output/rec_vietnamese_infer/inference.ymlAdded+267
ocr-studio/data/vietnamese_dict.txtAdded+224
ocr-studio/index.html+6-12