Spaces:
Running on Zero
Running on Zero
Commit ·
9338abc
1
Parent(s): 725c26b
Fix ZeroGPU startup
Browse files
app.py
CHANGED
|
@@ -7,6 +7,8 @@ from dataclasses import dataclass
|
|
| 7 |
from pathlib import Path
|
| 8 |
from typing import Any
|
| 9 |
|
|
|
|
|
|
|
| 10 |
import faiss
|
| 11 |
import gradio as gr
|
| 12 |
import numpy as np
|
|
@@ -127,11 +129,13 @@ if index.d != index_config["embedding_dimension"]:
|
|
| 127 |
|
| 128 |
# Load retrieval models once when the app starts.
|
| 129 |
embedding_model = SentenceTransformer(
|
| 130 |
-
EMBEDDING_MODEL_NAME
|
|
|
|
| 131 |
)
|
| 132 |
|
| 133 |
reranker = CrossEncoder(
|
| 134 |
-
RERANKER_MODEL_NAME
|
|
|
|
| 135 |
)
|
| 136 |
|
| 137 |
|
|
@@ -412,6 +416,7 @@ def enrich_candidates(
|
|
| 412 |
return enriched_results
|
| 413 |
|
| 414 |
|
|
|
|
| 415 |
def rerank_candidates(
|
| 416 |
query: str,
|
| 417 |
candidates: list[dict[str, Any]],
|
|
|
|
| 7 |
from pathlib import Path
|
| 8 |
from typing import Any
|
| 9 |
|
| 10 |
+
import spaces # Must be imported before torch-related libraries on ZeroGPU
|
| 11 |
+
|
| 12 |
import faiss
|
| 13 |
import gradio as gr
|
| 14 |
import numpy as np
|
|
|
|
| 129 |
|
| 130 |
# Load retrieval models once when the app starts.
|
| 131 |
embedding_model = SentenceTransformer(
|
| 132 |
+
EMBEDDING_MODEL_NAME,
|
| 133 |
+
device="cpu",
|
| 134 |
)
|
| 135 |
|
| 136 |
reranker = CrossEncoder(
|
| 137 |
+
RERANKER_MODEL_NAME,
|
| 138 |
+
device="cpu",
|
| 139 |
)
|
| 140 |
|
| 141 |
|
|
|
|
| 416 |
return enriched_results
|
| 417 |
|
| 418 |
|
| 419 |
+
@spaces.GPU(duration=60)
|
| 420 |
def rerank_candidates(
|
| 421 |
query: str,
|
| 422 |
candidates: list[dict[str, Any]],
|