| 
									
										
										
										
											2024-09-29 10:51:46 +08:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							| 
									
										
										
										
											2024-12-06 14:05:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-15 14:54:21 +08:00
										 |  |  | # PEP 723 metadata | 
					
						
							|  |  |  | # /// script | 
					
						
							|  |  |  | # requires-python = ">=3.10" | 
					
						
							|  |  |  | # dependencies = [ | 
					
						
							|  |  |  | #   "huggingface-hub", | 
					
						
							|  |  |  | #   "nltk", | 
					
						
							| 
									
										
										
										
											2025-04-07 11:58:46 +08:00
										 |  |  | #   "argparse", | 
					
						
							| 
									
										
										
										
											2025-02-15 14:54:21 +08:00
										 |  |  | # ] | 
					
						
							|  |  |  | # /// | 
					
						
							| 
									
										
										
										
											2024-09-29 10:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | from huggingface_hub import snapshot_download | 
					
						
							| 
									
										
										
										
											2025-05-27 09:28:52 +08:00
										 |  |  | from typing import Union | 
					
						
							| 
									
										
										
										
											2024-10-01 17:41:38 +08:00
										 |  |  | import nltk | 
					
						
							| 
									
										
										
										
											2024-09-29 10:51:46 +08:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2024-10-08 17:40:06 +08:00
										 |  |  | import urllib.request | 
					
						
							| 
									
										
										
										
											2025-04-07 11:58:46 +08:00
										 |  |  | import argparse | 
					
						
							| 
									
										
										
										
											2024-10-08 17:40:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-27 09:28:52 +08:00
										 |  |  | def get_urls(use_china_mirrors=False) -> Union[str, list[str]]: | 
					
						
							| 
									
										
										
										
											2025-04-07 11:58:46 +08:00
										 |  |  |     if use_china_mirrors: | 
					
						
							|  |  |  |         return [ | 
					
						
							|  |  |  |             "http://mirrors.tuna.tsinghua.edu.cn/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb", | 
					
						
							|  |  |  |             "http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_arm64.deb", | 
					
						
							|  |  |  |             "https://repo.huaweicloud.com/repository/maven/org/apache/tika/tika-server-standard/3.0.0/tika-server-standard-3.0.0.jar", | 
					
						
							|  |  |  |             "https://repo.huaweicloud.com/repository/maven/org/apache/tika/tika-server-standard/3.0.0/tika-server-standard-3.0.0.jar.md5", | 
					
						
							|  |  |  |             "https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken", | 
					
						
							| 
									
										
										
										
											2025-05-27 09:28:52 +08:00
										 |  |  |             ["https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.85/linux64/chrome-linux64.zip", "chrome-linux64-121-0-6167-85"], | 
					
						
							|  |  |  |             ["https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.85/linux64/chromedriver-linux64.zip", "chromedriver-linux64-121-0-6167-85"], | 
					
						
							| 
									
										
										
										
											2025-04-07 11:58:46 +08:00
										 |  |  |         ] | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         return [ | 
					
						
							|  |  |  |             "http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb", | 
					
						
							|  |  |  |             "http://ports.ubuntu.com/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_arm64.deb", | 
					
						
							|  |  |  |             "https://repo1.maven.org/maven2/org/apache/tika/tika-server-standard/3.0.0/tika-server-standard-3.0.0.jar", | 
					
						
							|  |  |  |             "https://repo1.maven.org/maven2/org/apache/tika/tika-server-standard/3.0.0/tika-server-standard-3.0.0.jar.md5", | 
					
						
							|  |  |  |             "https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken", | 
					
						
							|  |  |  |             "https://bit.ly/chrome-linux64-121-0-6167-85", | 
					
						
							|  |  |  |             "https://bit.ly/chromedriver-linux64-121-0-6167-85", | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2024-09-29 10:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | repos = [ | 
					
						
							|  |  |  |     "InfiniFlow/text_concat_xgb_v1.0", | 
					
						
							|  |  |  |     "InfiniFlow/deepdoc", | 
					
						
							| 
									
										
										
										
											2024-12-18 14:19:43 +08:00
										 |  |  |     "InfiniFlow/huqie", | 
					
						
							| 
									
										
										
										
											2024-09-29 10:51:46 +08:00
										 |  |  |     "BAAI/bge-large-zh-v1.5", | 
					
						
							|  |  |  |     "maidalun1020/bce-embedding-base_v1", | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def download_model(repo_id): | 
					
						
							| 
									
										
										
										
											2024-10-01 17:41:38 +08:00
										 |  |  |     local_dir = os.path.abspath(os.path.join("huggingface.co", repo_id)) | 
					
						
							| 
									
										
										
										
											2024-09-29 10:51:46 +08:00
										 |  |  |     os.makedirs(local_dir, exist_ok=True) | 
					
						
							| 
									
										
										
										
											2025-06-10 06:00:03 -07:00
										 |  |  |     snapshot_download(repo_id=repo_id, local_dir=local_dir) | 
					
						
							| 
									
										
										
										
											2024-09-29 10:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							| 
									
										
										
										
											2025-04-07 11:58:46 +08:00
										 |  |  |     parser = argparse.ArgumentParser(description='Download dependencies with optional China mirror support') | 
					
						
							|  |  |  |     parser.add_argument('--china-mirrors', action='store_true', help='Use China-accessible mirrors for downloads') | 
					
						
							|  |  |  |     args = parser.parse_args() | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     urls = get_urls(args.china_mirrors) | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2024-10-08 17:40:06 +08:00
										 |  |  |     for url in urls: | 
					
						
							| 
									
										
										
										
											2025-05-27 09:28:52 +08:00
										 |  |  |         download_url = url[0] if isinstance(url, list) else url | 
					
						
							|  |  |  |         filename = url[1] if isinstance(url, list) else url.split("/")[-1] | 
					
						
							|  |  |  |         print(f"Downloading {filename} from {download_url}...") | 
					
						
							| 
									
										
										
										
											2024-10-08 17:40:06 +08:00
										 |  |  |         if not os.path.exists(filename): | 
					
						
							| 
									
										
										
										
											2025-05-27 09:28:52 +08:00
										 |  |  |             urllib.request.urlretrieve(download_url, filename) | 
					
						
							| 
									
										
										
										
											2024-10-08 17:40:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-01 17:41:38 +08:00
										 |  |  |     local_dir = os.path.abspath('nltk_data') | 
					
						
							| 
									
										
										
										
											2024-10-02 19:41:56 +08:00
										 |  |  |     for data in ['wordnet', 'punkt', 'punkt_tab']: | 
					
						
							| 
									
										
										
										
											2024-10-01 17:41:38 +08:00
										 |  |  |         print(f"Downloading nltk {data}...") | 
					
						
							|  |  |  |         nltk.download(data, download_dir=local_dir) | 
					
						
							| 
									
										
										
										
											2024-10-02 19:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-29 10:51:46 +08:00
										 |  |  |     for repo_id in repos: | 
					
						
							| 
									
										
										
										
											2024-10-01 17:41:38 +08:00
										 |  |  |         print(f"Downloading huggingface repo {repo_id}...") | 
					
						
							| 
									
										
										
										
											2025-06-10 06:00:03 -07:00
										 |  |  |         download_model(repo_id) |