File size: 1,211 Bytes
bad6dd5
 
 
45c1857
bad6dd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45c1857
 
 
 
 
 
 
 
 
bad6dd5
 
45c1857
bad6dd5
 
 
45c1857
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
import os
from pathlib import Path
from urllib.request import urlretrieve
import streamlit as st

HOME_DIR = Path.home()
APP_CACHE = HOME_DIR / "olmo_demo"

OLMO_MODEL_FILE = os.environ.get("OLMO_MODEL_FILE", "OLMo-7B-Instruct-Q4_K_M.gguf")
OLMO_MODEL = APP_CACHE / OLMO_MODEL_FILE

def download_olmo_model(model_file: str | None = None, force=False) -> Path:
    if not OLMO_MODEL.exists() or force:
        if model_file is None:
            model_file = OLMO_MODEL_FILE
            olmo_model = OLMO_MODEL
        else:
            olmo_model = APP_CACHE / model_file
        olmo_model_url = f"https://huggingface.co/ssec-uw/OLMo-7B-Instruct-GGUF/resolve/main/{model_file}"
        
        st.info(f"Downloading model from {olmo_model_url} to {olmo_model}")
        try:
            APP_CACHE.mkdir(parents=True, exist_ok=True)
            urlretrieve(olmo_model_url, olmo_model)
            st.success("Download complete!")
        except Exception as e:
            st.error(f"Failed to download model: {str(e)}")
            raise
        return olmo_model
    else:
        st.info(f"Model already exists at {OLMO_MODEL}")
        return OLMO_MODEL

if __name__ == "__main__":
    download_olmo_model()