setup.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import glob
  15. import itertools
  16. import os
  17. from pathlib import Path
  18. from setuptools import find_packages, setup
  19. BASE_DEP_SPECS = {
  20. "aiohttp": ">= 3.9",
  21. "aistudio-sdk": ">=0.3.5",
  22. "bce-python-sdk": ">= 0.9",
  23. "beautifulsoup4": "",
  24. "chardet": "",
  25. "chinese-calendar": "",
  26. "colorlog": "",
  27. "decord": "== 0.6.0; (platform_machine == 'x86_64' or platform_machine == 'AMD64') and sys_platform != 'darwin'",
  28. "einops": "",
  29. "faiss-cpu": "",
  30. "filelock": "",
  31. "ftfy": "",
  32. "GPUtil": ">= 1.4",
  33. "huggingface-hub": "",
  34. "imagesize": "",
  35. "Jinja2": "",
  36. "joblib": "",
  37. "langchain": ">= 0.2",
  38. "langchain-community": ">= 0.2",
  39. "langchain-core": "",
  40. "langchain-openai": ">= 0.1",
  41. "lxml": "",
  42. "matplotlib": "",
  43. "modelscope": ">=1.28.0",
  44. "numpy": ">= 1.24",
  45. "openai": ">= 1.63",
  46. "opencv-contrib-python": "== 4.10.0.84",
  47. "openpyxl": "",
  48. "packaging": "",
  49. "pandas": ">= 1.3",
  50. "pillow": "",
  51. "premailer": "",
  52. "prettytable": "",
  53. "py-cpuinfo": "",
  54. "pyclipper": "",
  55. "pycocotools": "<= 2.0.8", # pycocotools upgrade incompatible since 2.0.9
  56. "pydantic": ">= 2",
  57. "pypdfium2": ">= 4",
  58. "PyYAML": "== 6.0.2",
  59. "regex": "",
  60. "requests": "",
  61. "ruamel.yaml": "",
  62. "safetensors": [
  63. "@ https://paddle-whl.bj.bcebos.com/nightly/cu126/safetensors/safetensors-0.6.2.dev0-cp38-abi3-linux_x86_64.whl ; sys_platform == 'linux'",
  64. "; sys_platform != 'linux'",
  65. ],
  66. "scikit-image": "",
  67. "scikit-learn": "",
  68. "sentencepiece": "",
  69. "shapely": "",
  70. "soundfile": "",
  71. "tiktoken": "",
  72. "tokenizers": ">= 0.19",
  73. "tqdm": "",
  74. "typing-extensions": "",
  75. "ujson": "",
  76. }
  77. REQUIRED_DEPS = [
  78. "aistudio-sdk",
  79. "chardet",
  80. "colorlog",
  81. "filelock",
  82. "huggingface-hub",
  83. "modelscope",
  84. "numpy",
  85. "packaging",
  86. # Currently it is not easy to make `pandas` optional
  87. "pandas",
  88. "pillow",
  89. "prettytable",
  90. "py-cpuinfo",
  91. "pydantic",
  92. "PyYAML",
  93. "requests",
  94. "ruamel.yaml",
  95. "typing-extensions",
  96. "ujson",
  97. ]
  98. EXTRAS = {
  99. "base": {
  100. "cv": [
  101. "faiss-cpu",
  102. "matplotlib",
  103. "opencv-contrib-python",
  104. "pycocotools",
  105. # Currently `pypdfium2` is required by the image batch sampler
  106. "pypdfium2",
  107. "scikit-image",
  108. ],
  109. "multimodal": [
  110. "einops",
  111. "ftfy",
  112. "GPUtil",
  113. "Jinja2",
  114. "opencv-contrib-python",
  115. # For the same reason as in `cv`
  116. "pypdfium2",
  117. "regex",
  118. "safetensors",
  119. "sentencepiece",
  120. "tiktoken",
  121. ],
  122. "ie": [
  123. "ftfy",
  124. "imagesize",
  125. "langchain",
  126. "langchain-community",
  127. "langchain-core",
  128. "langchain-openai",
  129. "lxml",
  130. "openai",
  131. "opencv-contrib-python",
  132. "openpyxl",
  133. "premailer",
  134. "pyclipper",
  135. "pypdfium2",
  136. "scikit-learn",
  137. "shapely",
  138. "tokenizers",
  139. ],
  140. "trans": [
  141. "beautifulsoup4",
  142. "ftfy",
  143. "imagesize",
  144. "lxml",
  145. "openai",
  146. "opencv-contrib-python",
  147. "openpyxl",
  148. "premailer",
  149. "pyclipper",
  150. "pypdfium2",
  151. "scikit-learn",
  152. "shapely",
  153. "tokenizers",
  154. ],
  155. "ocr-core": [
  156. "imagesize",
  157. "opencv-contrib-python",
  158. "pyclipper",
  159. "pypdfium2",
  160. "shapely",
  161. ],
  162. "ocr": [
  163. "einops",
  164. "ftfy",
  165. "imagesize",
  166. "Jinja2",
  167. "lxml",
  168. "opencv-contrib-python",
  169. "openpyxl",
  170. "premailer",
  171. "pyclipper",
  172. "pypdfium2",
  173. "regex",
  174. "safetensors",
  175. "scikit-learn",
  176. "sentencepiece",
  177. "shapely",
  178. "tiktoken",
  179. "tokenizers",
  180. "python-bidi",
  181. ],
  182. "speech": [
  183. "ftfy",
  184. "Jinja2",
  185. "regex",
  186. "soundfile",
  187. "tqdm",
  188. ],
  189. "ts": [
  190. "chinese-calendar",
  191. "joblib",
  192. "matplotlib",
  193. "scikit-learn",
  194. ],
  195. "video": [
  196. "decord",
  197. "opencv-contrib-python",
  198. ],
  199. },
  200. "plugins": {
  201. "genai-client": [
  202. "openai >= 1.63",
  203. ],
  204. "genai-sglang-server": [
  205. "einops",
  206. "sglang [all] == 0.5.2",
  207. "torch == 2.8.0",
  208. "transformers",
  209. "xformers",
  210. ],
  211. "genai-vllm-server": [
  212. "einops",
  213. "torch == 2.8.0",
  214. "transformers",
  215. "uvloop",
  216. "vllm == 0.10.2",
  217. "xformers",
  218. ],
  219. "paddle2onnx": [
  220. "paddle2onnx == 2.0.2rc3",
  221. ],
  222. "serving": [
  223. "aiohttp >= 3.9",
  224. "bce-python-sdk >= 0.9",
  225. "fastapi >= 0.110",
  226. "filetype >= 1.2",
  227. "opencv-contrib-python == 4.10.0.84",
  228. "pypdfium2 >= 4",
  229. "starlette >= 0.36",
  230. "uvicorn >= 0.16",
  231. "yarl >= 1.9",
  232. ],
  233. },
  234. }
  235. def _get_dep_specs(deps):
  236. dep_specs = []
  237. for dep in deps:
  238. val = BASE_DEP_SPECS[dep]
  239. if not isinstance(val, list):
  240. val = [val]
  241. for v in val:
  242. if not v:
  243. dep_specs.append(dep)
  244. else:
  245. dep_specs.append(dep + " " + v)
  246. return dep_specs
  247. def _sort_dep_specs(dep_specs):
  248. return sorted(dep_specs, key=str.lower)
  249. def readme():
  250. """get readme"""
  251. with open("README.md", "r", encoding="utf-8") as file:
  252. return file.read()
  253. def dependencies():
  254. dep_specs = _get_dep_specs(REQUIRED_DEPS)
  255. return _sort_dep_specs(dep_specs)
  256. def extras():
  257. dic = {}
  258. base_dep_specs = set()
  259. for extra_name, extra_deps in EXTRAS["base"].items():
  260. extra_dep_specs = _get_dep_specs(extra_deps)
  261. dic[extra_name] = _sort_dep_specs(extra_dep_specs)
  262. base_dep_specs.update(extra_dep_specs)
  263. dic["base"] = _sort_dep_specs(base_dep_specs)
  264. for extra_name, extra_dep_specs in EXTRAS["plugins"].items():
  265. dic[extra_name] = _sort_dep_specs(extra_dep_specs)
  266. return dic
  267. def version():
  268. """get version"""
  269. with open(os.path.join("paddlex", ".version"), "r") as file:
  270. return file.read().rstrip()
  271. def get_data_files(directory: str, filetypes: list = None):
  272. all_files = []
  273. filetypes = filetypes or []
  274. for root, _, files in os.walk(directory):
  275. rel_root = os.path.relpath(root, directory)
  276. for file in files:
  277. filepath = os.path.join(rel_root, file)
  278. filetype = os.path.splitext(file)[1][1:]
  279. if filetype in filetypes:
  280. all_files.append(filepath)
  281. return all_files
  282. def packages_and_package_data():
  283. """get packages and package_data"""
  284. def _recursively_find(pattern, exts=None):
  285. for dir_ in glob.iglob(pattern):
  286. for root, _, files in os.walk(dir_):
  287. for f in files:
  288. if exts is not None:
  289. ext = os.path.splitext(f)[1]
  290. if ext not in exts:
  291. continue
  292. yield os.path.join(root, f)
  293. pkgs = find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"])
  294. pkg_data = []
  295. for p in itertools.chain(
  296. _recursively_find("paddlex/configs/*", exts=[".yml", ".yaml"]),
  297. ):
  298. pkg_data.append(Path(p).relative_to("paddlex").as_posix())
  299. pipeline_config = [
  300. Path(p).relative_to("paddlex").as_posix()
  301. for p in glob.glob("paddlex/pipelines/*.yaml")
  302. ]
  303. pkg_data.extend(pipeline_config)
  304. pkg_data.append("inference/pipelines/ppchatocrv3/ch_prompt.yaml")
  305. pkg_data.append(".version")
  306. pkg_data.append("hpip_links.html")
  307. pkg_data.append("hpip_links_cu12.html")
  308. pkg_data.append("inference/utils/hpi_model_info_collection.json")
  309. genai_chat_templates = [
  310. Path(p).relative_to("paddlex").as_posix()
  311. for p in glob.glob("paddlex/inference/genai/chat_templates/*.jinja")
  312. ]
  313. pkg_data.extend(genai_chat_templates)
  314. pkg_data.extend("inference/genai/models/")
  315. ops_file_dir = "paddlex/ops"
  316. ops_file_types = ["h", "hpp", "cpp", "cc", "cu"]
  317. return pkgs, {
  318. "paddlex.ops": get_data_files(ops_file_dir, ops_file_types),
  319. "paddlex": pkg_data,
  320. }
  321. if __name__ == "__main__":
  322. pkgs, pkg_data = packages_and_package_data()
  323. s = setup(
  324. name="paddlex",
  325. version=version(),
  326. description=("Low-code development tool based on PaddlePaddle."),
  327. long_description=readme(),
  328. long_description_content_type="text/markdown",
  329. author="PaddlePaddle Authors",
  330. author_email="",
  331. install_requires=dependencies(),
  332. extras_require=extras(),
  333. packages=pkgs,
  334. package_data=pkg_data,
  335. entry_points={
  336. "console_scripts": [
  337. "paddlex = paddlex.__main__:console_entry",
  338. "paddlex_genai_server = paddlex.inference.genai.server:main",
  339. ],
  340. "vllm.general_plugins": [
  341. "register_paddlex_genai_models = paddlex.inference.genai.backends.vllm:register_models"
  342. ],
  343. },
  344. # PyPI package information
  345. classifiers=[
  346. "Development Status :: 4 - Beta",
  347. "Intended Audience :: Developers",
  348. "Intended Audience :: Education",
  349. "Intended Audience :: Science/Research",
  350. "Programming Language :: Python :: 3.8",
  351. "Programming Language :: Python :: 3.9",
  352. "Programming Language :: Python :: 3.10",
  353. "Programming Language :: Python :: 3.11",
  354. "Programming Language :: Python :: 3.12",
  355. "Topic :: Scientific/Engineering",
  356. "Topic :: Scientific/Engineering :: Mathematics",
  357. "Topic :: Scientific/Engineering :: Artificial Intelligence",
  358. "Topic :: Software Development",
  359. "Topic :: Software Development :: Libraries",
  360. "Topic :: Software Development :: Libraries :: Python Modules",
  361. ],
  362. license="Apache-2.0",
  363. license_files=["LICENSE"],
  364. keywords=["paddlepaddle"],
  365. )