WIP
This commit is contained in:
@@ -37,16 +37,41 @@ class InferenceClient:
|
||||
# Assuming this file is in core/inference_client.py
|
||||
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
server_script = os.path.join(root_dir, "server", "main.py")
|
||||
|
||||
# Use system python (assumed to have dependencies via Nix/venv)
|
||||
# In user's environment, 'python' should refer to the environment python
|
||||
python_cmd = "python"
|
||||
|
||||
# Start process
|
||||
|
||||
# Prepare environment variables for server process
|
||||
server_env = os.environ.copy()
|
||||
|
||||
# Load environment variables from .env file if it exists
|
||||
env_file = os.path.join(root_dir, ".env")
|
||||
if os.path.exists(env_file):
|
||||
with open(env_file, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#') and '=' in line:
|
||||
key, value = line.split('=', 1)
|
||||
server_env[key] = value
|
||||
print(f"[FaceMask] Loaded environment from: {env_file}")
|
||||
|
||||
# Ensure PYTHONPATH includes project root
|
||||
pythonpath = server_env.get('PYTHONPATH', '')
|
||||
if pythonpath:
|
||||
server_env['PYTHONPATH'] = f"{root_dir}:{pythonpath}"
|
||||
else:
|
||||
server_env['PYTHONPATH'] = root_dir
|
||||
|
||||
# If there's a venv in the project, add it to PATH
|
||||
venv_bin = os.path.join(root_dir, ".venv", "bin")
|
||||
if os.path.isdir(venv_bin):
|
||||
current_path = server_env.get('PATH', '')
|
||||
server_env['PATH'] = f"{venv_bin}:{current_path}"
|
||||
print(f"[FaceMask] Using venv from: {venv_bin}")
|
||||
|
||||
# Start process with 'python' command (will use venv if PATH is set correctly)
|
||||
self.server_process = subprocess.Popen(
|
||||
[python_cmd, server_script],
|
||||
["python", server_script],
|
||||
cwd=root_dir,
|
||||
text=True,
|
||||
env=server_env,
|
||||
preexec_fn=os.setsid, # Create new process group
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user