Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +10 -1
src/streamlit_app.py
CHANGED
|
@@ -5,8 +5,13 @@ from PIL import Image
|
|
| 5 |
import numpy as np
|
| 6 |
import io
|
| 7 |
import requests
|
|
|
|
| 8 |
from typing import List, Tuple
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Configure page
|
| 11 |
st.set_page_config(
|
| 12 |
page_title="CLIP Classifier",
|
|
@@ -18,8 +23,12 @@ st.set_page_config(
|
|
| 18 |
def load_clip_model():
|
| 19 |
"""Load CLIP model and preprocessing function"""
|
| 20 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 22 |
-
model, preprocess = clip.load("ViT-B/32", device=device)
|
| 23 |
return model, preprocess, device
|
| 24 |
except Exception as e:
|
| 25 |
st.error(f"Error loading CLIP model: {e}")
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
import io
|
| 7 |
import requests
|
| 8 |
+
import os
|
| 9 |
from typing import List, Tuple
|
| 10 |
|
| 11 |
+
# Set cache directories to writable locations
|
| 12 |
+
os.environ['TORCH_HOME'] = '/tmp/torch_cache'
|
| 13 |
+
os.environ['HF_HOME'] = '/tmp/hf_cache'
|
| 14 |
+
|
| 15 |
# Configure page
|
| 16 |
st.set_page_config(
|
| 17 |
page_title="CLIP Classifier",
|
|
|
|
| 23 |
def load_clip_model():
|
| 24 |
"""Load CLIP model and preprocessing function"""
|
| 25 |
try:
|
| 26 |
+
# Ensure cache directories exist
|
| 27 |
+
os.makedirs('/tmp/torch_cache', exist_ok=True)
|
| 28 |
+
os.makedirs('/tmp/clip_models', exist_ok=True)
|
| 29 |
+
|
| 30 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 31 |
+
model, preprocess = clip.load("ViT-B/32", device=device, download_root="/tmp/clip_models")
|
| 32 |
return model, preprocess, device
|
| 33 |
except Exception as e:
|
| 34 |
st.error(f"Error loading CLIP model: {e}")
|