import subprocess import time import requests def is_ollama_running(): try: r = requests.get("http://localhost:11434") return r.status_code == 200 except Exception: return False def start_ollama_model(model_name="llama3"): print(f"🚀 Starting Ollama model: {model_name}") subprocess.Popen(["ollama", "run", model_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) print("⏳ Waiting for Ollama to be ready...") for _ in range(20): # wait up to ~10 seconds if is_ollama_running(): print("✅ Ollama is up!") return True time.sleep(0.5) print("❌ Ollama failed to start or is not responding.") return False