mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-01 18:21:30 +08:00
Add a complete example demonstrating dirty workers with sentence-transformers for text embeddings via FastAPI: - EmbeddingApp DirtyApp that loads and manages the ML model - FastAPI endpoints for /embed and /health - Docker and docker-compose configuration - Integration tests with numpy similarity checks - GitHub Actions CI workflow
15 lines
370 B
Python
15 lines
370 B
Python
from gunicorn.dirty.app import DirtyApp
|
|
|
|
|
|
class EmbeddingApp(DirtyApp):
|
|
def init(self):
|
|
from sentence_transformers import SentenceTransformer
|
|
self.model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
|
|
def embed(self, texts):
|
|
embeddings = self.model.encode(texts)
|
|
return embeddings.tolist()
|
|
|
|
def close(self):
|
|
del self.model
|