Spaces:
Running
Running
File size: 929 Bytes
162d479 8574870 162d479 | 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 | import subprocess
import sys
import os
import signal
def start_backend():
env = os.environ.copy()
# Ensure backend path is on PYTHONPATH
backend_dir = os.path.join(os.getcwd(), "deepshell-backend")
env["PYTHONPATH"] = backend_dir + os.pathsep + env.get("PYTHONPATH", "")
# Respect env vars already set in shell (PROVIDER, GROQ_API_KEY, LLM_MODEL, PORT)
# Run the deepshell package (__main__.py) which exposes the FastAPI app
cmd = [sys.executable, "-m", "deepshell"]
process = subprocess.Popen(cmd, env=env, cwd=backend_dir)
print(f"DeepShell backend started with PID {process.pid}")
return process
def main():
backend_process = start_backend()
try:
backend_process.wait()
except KeyboardInterrupt:
print("Stopping DeepShell backend...")
backend_process.send_signal(signal.SIGINT)
backend_process.wait()
if __name__ == "__main__":
main()
|