Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

feat(language): add FT LANG cache directory setup

myhloli57380cbed56a
diff --git a/magic_pdf/libs/language.py b/magic_pdf/libs/language.py
index bddb5475..396c9008 100644
--- a/magic_pdf/libs/language.py
+++ b/magic_pdf/libs/language.py
@@ -1,8 +1,19 @@
+import os
import unicodedata
+
+if not os.getenv("FTLANG_CACHE"):
+ current_file_path = os.path.abspath(__file__)
+ current_dir = os.path.dirname(current_file_path)
+ root_dir = os.path.dirname(current_dir)
+ ftlang_cache_dir = os.path.join(root_dir, 'resources', 'fasttext-langdetect')
+ os.environ["FTLANG_CACHE"] = str(ftlang_cache_dir)
+ # print(os.getenv("FTLANG_CACHE"))
+
from fast_langdetect import detect_language
def detect_lang(text: str) -> str:
+
if len(text) == 0:
return ""
try:
@@ -18,6 +29,7 @@ def detect_lang(text: str) -> str:
if __name__ == '__main__':
+ print(os.getenv("FTLANG_CACHE"))
print(detect_lang("This is a test."))
print(detect_lang("<html>This is a test</html>"))
print(detect_lang("这个是中文测试。"))
diff --git a/magic_pdf/resources/fasttext-langdetect/lid.176.ftz b/magic_pdf/resources/fasttext-langdetect/lid.176.ftz
new file mode 100644
index 00000000..1fb85b35
Binary files /dev/null and b/magic_pdf/resources/fasttext-langdetect/lid.176.ftz differ