setup.py 11 KB

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