import os import requests os.makedirs("model", exist_ok=True) model_path = "model/Mistral-7b-instruct-v0.3.Q4_K_M.gguf" model_url = "https://huggingface.co/MaziyarPanahi/Mistral-7B-Instruct-v0.3-GGUF/resolve/main/Mistral-7B-Instruct-v0.3.IQ1_M.gguf?download=true" # Expect token to be passed as environment variable (safe for Spaces) HF_TOKEN = os.getenv("HF_TOKEN") if not HF_TOKEN: raise ValueError("❌ HF_TOKEN environment variable not found. Set it in your Space's secrets.") headers = { "Authorization": f"Bearer {HF_TOKEN}" } if not os.path.exists(model_path): print("🔁 Downloading model from Hugging Face...") with requests.get(model_url, headers=headers, stream=True) as r: r.raise_for_status() with open(model_path, "wb") as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) print("✅ Download complete.")