Spaces:
Running
Running
Jin Zhu commited on
Commit ·
40bdd15
1
Parent(s): 2d7d536
add cache dir
Browse files- src/app.py +7 -0
src/app.py
CHANGED
|
@@ -21,6 +21,13 @@ def load_model(from_pretrained, base_model, cache_dir, device):
|
|
| 21 |
Load and cache the model to avoid reloading on every user interaction.
|
| 22 |
This function runs only once when the app starts or when parameters change.
|
| 23 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
with st.spinner("🔄 Loading model... This may take a moment on first launch."):
|
| 25 |
model = ComputeScore.from_pretrained(
|
| 26 |
from_pretrained,
|
|
|
|
| 21 |
Load and cache the model to avoid reloading on every user interaction.
|
| 22 |
This function runs only once when the app starts or when parameters change.
|
| 23 |
"""
|
| 24 |
+
is_hf_space = os.environ.get('SPACE_ID') is not None
|
| 25 |
+
if is_hf_space:
|
| 26 |
+
cache_dir = None
|
| 27 |
+
device = 'cpu'
|
| 28 |
+
print("Using **CPU** now!")
|
| 29 |
+
else:
|
| 30 |
+
cache_dir = cache_dir
|
| 31 |
with st.spinner("🔄 Loading model... This may take a moment on first launch."):
|
| 32 |
model = ComputeScore.from_pretrained(
|
| 33 |
from_pretrained,
|