Spaces:
Sleeping
Sleeping
Update setup.py
Browse files
setup.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
from pathlib import Path
|
3 |
from urllib.request import urlretrieve
|
|
|
4 |
|
5 |
HOME_DIR = Path.home()
|
6 |
APP_CACHE = HOME_DIR / "olmo_demo"
|
@@ -9,18 +10,6 @@ OLMO_MODEL_FILE = os.environ.get("OLMO_MODEL_FILE", "OLMo-7B-Instruct-Q4_K_M.ggu
|
|
9 |
OLMO_MODEL = APP_CACHE / OLMO_MODEL_FILE
|
10 |
|
11 |
def download_olmo_model(model_file: str | None = None, force=False) -> Path:
|
12 |
-
"""Download the OLMO model from the Hugging Face model hub.
|
13 |
-
Parameters
|
14 |
-
----------
|
15 |
-
model_file : str | None, optional
|
16 |
-
The name of the model file to download, by default None
|
17 |
-
force : bool, optional
|
18 |
-
Whether to force the download even if the file already exists, by default False
|
19 |
-
Returns
|
20 |
-
-------
|
21 |
-
pathlib.Path
|
22 |
-
The path to the downloaded model file
|
23 |
-
"""
|
24 |
if not OLMO_MODEL.exists() or force:
|
25 |
if model_file is None:
|
26 |
model_file = OLMO_MODEL_FILE
|
@@ -28,14 +17,19 @@ def download_olmo_model(model_file: str | None = None, force=False) -> Path:
|
|
28 |
else:
|
29 |
olmo_model = APP_CACHE / model_file
|
30 |
olmo_model_url = f"https://huggingface.co/ssec-uw/OLMo-7B-Instruct-GGUF/resolve/main/{model_file}"
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
return olmo_model
|
35 |
else:
|
36 |
-
|
37 |
return OLMO_MODEL
|
38 |
|
39 |
if __name__ == "__main__":
|
40 |
-
|
41 |
-
download_olmo_model()
|
|
|
1 |
import os
|
2 |
from pathlib import Path
|
3 |
from urllib.request import urlretrieve
|
4 |
+
import streamlit as st
|
5 |
|
6 |
HOME_DIR = Path.home()
|
7 |
APP_CACHE = HOME_DIR / "olmo_demo"
|
|
|
10 |
OLMO_MODEL = APP_CACHE / OLMO_MODEL_FILE
|
11 |
|
12 |
def download_olmo_model(model_file: str | None = None, force=False) -> Path:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
if not OLMO_MODEL.exists() or force:
|
14 |
if model_file is None:
|
15 |
model_file = OLMO_MODEL_FILE
|
|
|
17 |
else:
|
18 |
olmo_model = APP_CACHE / model_file
|
19 |
olmo_model_url = f"https://huggingface.co/ssec-uw/OLMo-7B-Instruct-GGUF/resolve/main/{model_file}"
|
20 |
+
|
21 |
+
st.info(f"Downloading model from {olmo_model_url} to {olmo_model}")
|
22 |
+
try:
|
23 |
+
APP_CACHE.mkdir(parents=True, exist_ok=True)
|
24 |
+
urlretrieve(olmo_model_url, olmo_model)
|
25 |
+
st.success("Download complete!")
|
26 |
+
except Exception as e:
|
27 |
+
st.error(f"Failed to download model: {str(e)}")
|
28 |
+
raise
|
29 |
return olmo_model
|
30 |
else:
|
31 |
+
st.info(f"Model already exists at {OLMO_MODEL}")
|
32 |
return OLMO_MODEL
|
33 |
|
34 |
if __name__ == "__main__":
|
35 |
+
download_olmo_model()
|
|