File size: 904 Bytes
1a5a672
 
 
 
 
d42a9c3
4d4fd9b
bedff17
485c3aa
 
 
 
 
 
 
 
 
 
bedff17
485c3aa
 
bedff17
 
 
 
485c3aa
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
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.")