Spaces:
Running on Zero
Running on Zero
Update rag_engine.py
Browse files- rag_engine.py +5 -6
rag_engine.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
import html
|
| 3 |
import re
|
|
|
|
| 4 |
import threading
|
| 5 |
from dataclasses import dataclass
|
| 6 |
import faiss
|
|
@@ -208,15 +209,13 @@ _LOCAL_MODEL_LOCK = threading.Lock()
|
|
| 208 |
|
| 209 |
def get_embedding_device() -> str:
|
| 210 |
"""
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
Fall back to CPU (automatically, if GPU not ready)
|
| 214 |
"""
|
| 215 |
|
| 216 |
-
if
|
| 217 |
-
return "
|
| 218 |
|
| 219 |
-
return "cpu"
|
| 220 |
|
| 221 |
|
| 222 |
def get_embedder() -> SentenceTransformer:
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
import html
|
| 3 |
import re
|
| 4 |
+
import os
|
| 5 |
import threading
|
| 6 |
from dataclasses import dataclass
|
| 7 |
import faiss
|
|
|
|
| 209 |
|
| 210 |
def get_embedding_device() -> str:
|
| 211 |
"""
|
| 212 |
+
embedding device
|
|
|
|
|
|
|
| 213 |
"""
|
| 214 |
|
| 215 |
+
if os.getenv("SPACES_ZERO_GPU"):
|
| 216 |
+
return "cpu"
|
| 217 |
|
| 218 |
+
return "cuda" if torch.cuda.is_available() else "cpu"
|
| 219 |
|
| 220 |
|
| 221 |
def get_embedder() -> SentenceTransformer:
|