File size: 1,154 Bytes
e7ca840
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Runtime installation of the gigacheck package without its pinned deps.

gigacheck pins ``torch==2.3.1`` in its ``install_requires``, which conflicts
with the ``torch==2.8.0`` this demo needs. Installing gigacheck with
``--no-deps`` lets pip skip that pin entirely; the inference path only needs
``numpy``, ``scipy``, ``dacite`` and ``omegaconf`` on top of torch/transformers,
which are declared in ``requirements.txt`` and installed normally.
"""

from __future__ import annotations

import importlib.util
import subprocess
import sys

from loguru import logger

GIGACHECK_SPEC = "git+https://github.com/ai-forever/gigacheck"


def ensure_gigacheck() -> None:
    """Install the gigacheck package on first run, skipping its pinned deps.

    No-op when gigacheck is already importable (e.g. installed in the image),
    so repeated app restarts do not reinstall it.
    """
    if importlib.util.find_spec("gigacheck") is not None:
        return
    logger.info("Installing gigacheck with --no-deps from {}", GIGACHECK_SPEC)
    subprocess.run(
        [sys.executable, "-m", "pip", "install", "--no-deps", GIGACHECK_SPEC],
        check=True,
    )