Spaces:
Sleeping
Sleeping
File size: 1,103 Bytes
33e3354 21094b9 33e3354 | 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 35 36 37 | import subprocess
import time
import urllib.request
import sys
print("1. Starting Ollama server in the background...")
server = subprocess.Popen(["ollama", "serve"])
print("2. Waiting for server to wake up...")
ready = False
for i in range(30): # Give it up to 30 seconds
try:
if urllib.request.urlopen("http://127.0.0.1:7860").getcode() == 200:
ready = True
break
except Exception:
time.sleep(1)
if not ready:
print("Error: Ollama server failed to start.")
server.kill()
sys.exit(1)
print("3. Server is up! Pulling base model and creating quant-agent...")
try:
# This automatically downloads gemma3:4b and applies your Modelfile
subprocess.run(["ollama", "create", "quant-agent", "-f", "/app/Tools.modelfile"], check=True)
print("Model successfully baked!")
except subprocess.CalledProcessError:
print("Error during model creation.")
server.kill()
sys.exit(1)
print("4. Shutting down background server to finalize Docker layer...")
server.terminate()
server.wait()
print("Build script complete. Exiting cleanly.") |