Spaces:
Running on Zero
Running on Zero
Use lazy TextEncoderAPI client in API-only mode (no startup fallback)
Browse files
kimodo/model/text_encoder_api.py
CHANGED
|
@@ -19,10 +19,18 @@ class TextEncoderAPI:
|
|
| 19 |
"""Text encoder API client for motion generation."""
|
| 20 |
|
| 21 |
def __init__(self, url: str):
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
self.device = "cpu"
|
| 24 |
self.dtype = torch.float
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def _create_np_random_name(self):
|
| 27 |
import uuid
|
| 28 |
|
|
@@ -53,7 +61,7 @@ class TextEncoderAPI:
|
|
| 53 |
filename = self._create_np_random_name()
|
| 54 |
|
| 55 |
# Use a long result timeout to tolerate text-encoder cold-start (LLM2Vec model load ~60-120s).
|
| 56 |
-
result = self.
|
| 57 |
text=text,
|
| 58 |
filename=filename,
|
| 59 |
api_name="/DemoWrapper",
|
|
|
|
| 19 |
"""Text encoder API client for motion generation."""
|
| 20 |
|
| 21 |
def __init__(self, url: str):
|
| 22 |
+
# Keep startup resilient: do not connect during app/model initialization.
|
| 23 |
+
# In strict API mode, we only attempt network calls when embeddings are requested.
|
| 24 |
+
self.url = url
|
| 25 |
+
self.client = None
|
| 26 |
self.device = "cpu"
|
| 27 |
self.dtype = torch.float
|
| 28 |
|
| 29 |
+
def _get_client(self):
|
| 30 |
+
if self.client is None:
|
| 31 |
+
self.client = Client(self.url, verbose=False)
|
| 32 |
+
return self.client
|
| 33 |
+
|
| 34 |
def _create_np_random_name(self):
|
| 35 |
import uuid
|
| 36 |
|
|
|
|
| 61 |
filename = self._create_np_random_name()
|
| 62 |
|
| 63 |
# Use a long result timeout to tolerate text-encoder cold-start (LLM2Vec model load ~60-120s).
|
| 64 |
+
result = self._get_client().submit(
|
| 65 |
text=text,
|
| 66 |
filename=filename,
|
| 67 |
api_name="/DemoWrapper",
|