Spaces:
Sleeping
Sleeping
File size: 976 Bytes
8f842e4 c4d1eaa 8f842e4 c4d1eaa 8f842e4 c4d1eaa 8f842e4 c4d1eaa 8f842e4 c4d1eaa 8f842e4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
from fastapi import FastAPI, HTTPException
from app.models import EmbedRequest, EmbedResponse
from app.embeddings import embed_text
from app.logger import logger
app = FastAPI(
title="Embedding API",
description="A simple API to generate text embeddings using Microsoft's `multilingual-e5-large` model.",
version="1.0.0",
)
@app.post("/embed", response_model=EmbedResponse)
async def embed(request: EmbedRequest) -> dict[str, list[list[float]]]:
"""Generate embeddings for a list of texts."""
logger.info("Generating embeddings...")
try:
vectors = embed_text(request.texts)
logger.info("Embeddings generated successfully!")
return {"embeddings": vectors}
except Exception as e:
logger.exception("Error generating embeddings")
raise HTTPException(status_code=500, detail=str(e))
@app.get("/health")
async def health_check() -> dict[str, str]:
"""Health check endpoint."""
return {"status": "ok"}
|