Download app.py from StyleKeeperAI/style-keeper-embeddings: direct link, hf CLI and curl.
- Browser
- Download file 661 Bytes
-
https://huggingface.co/spaces/StyleKeeperAI/style-keeper-embeddings/resolve/main/app.py
- Command line
-
hf download hf://spaces/StyleKeeperAI/style-keeper-embeddings/app.py
-
curl -L -o app.py https://huggingface.co/spaces/StyleKeeperAI/style-keeper-embeddings/resolve/main/app.py
661 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from sentence_transformers import SentenceTransformer | |
| import uvicorn | |
| app = FastAPI() | |
| model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2") | |
| class EmbedRequest(BaseModel): | |
| inputs: str | list[str] | |
| def embed(req: EmbedRequest): | |
| texts = req.inputs if isinstance(req.inputs, list) else [req.inputs] | |
| embeddings = model.encode(texts, normalize_embeddings=True) | |
| return embeddings.tolist() | |
| def health(): | |
| return {"status": "ok", "model": "all-MiniLM-L6-v2"} | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |