MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / _ensure_versions

Function _ensure_versions

demo/app.py:10–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8# Version guard
9# =====================
10def _ensure_versions():
11 import importlib, subprocess, sys
12
13 def get_version(pkg):
14 try:
15 m = importlib.import_module(pkg)
16 return getattr(m, "__version__", "0")
17 except Exception:
18 return "0"
19
20 try:
21 from packaging.version import Version
22 except ImportError:
23 # 安装packaging,确保下面版本比较能用
24 subprocess.check_call([sys.executable, "-m", "pip", "install", "packaging"])
25 from packaging.version import Version
26
27 # 检查 huggingface_hub
28 hub_ver = get_version("huggingface_hub")
29 hv = Version(hub_ver)
30
31 required_min = Version("0.24.0")
32 required_max = Version("1.0.0")
33
34 hub_ok = required_min <= hv < required_max
35
36 if not hub_ok:
37 print(f"[INFO] huggingface_hub=={hub_ver} not in range "
38 f"[{required_min}, {required_max}), reinstalling...")
39 subprocess.check_call([
40 sys.executable, "-m", "pip", "install",
41 "huggingface-hub==0.27.1",
42 "transformers==4.48.0",
43 "--force-reinstall", "--no-deps"
44 ])
45 else:
46 print(f"[INFO] huggingface_hub version OK: {hub_ver}")
47
48_ensure_versions()
49

Callers 1

app.pyFile · 0.85

Calls 1

get_versionFunction · 0.85

Tested by

no test coverage detected