ramouch/English-Encoder
0
๐ค English Sentence Encoder API (FastAPI + SentenceTransformers)
This repository provides an easy-to-use English text embedding API using FastAPI and the high-performance all-MiniLM-L6-v2 model from SentenceTransformers.
Perfect for semantic similarity, search, and clustering tasks where compact sentence embeddings are needed.
๐ Features
- โจ Uses
all-MiniLM-L6-v2: Fast & accurate transformer-based model - โก Lightweight, suitable for CPU
- ๐ RESTful API powered by FastAPI
- ๐ Accepts single or batch sentence inputs
- ๐งช Local testing & container-friendly
๐ง Model Details
โ Ideal for production systems needing fast, low-latency sentence embeddings.
๐ฆ API Endpoint
POST /encode
Input: Raw text or list of sentences Output: List of float embeddings
โ Example Request:
curl -X POST http://localhost:7860/encode \
-H "Content-Type: application/json" \
-d '{"text": "How are you today?"}'๐ค Example Response:
{
"embedding": [
-0.0212, 0.0543, -0.0746, ...
]
}๐งช Local Development
1. Install dependencies
pip install -r requirements.txt2. Run the API
python app.py3. Test the endpoint
curl -X POST http://localhost:7860/encode \
-H "Content-Type: application/json" \
-d '{"text": "Example sentence."}'๐ณ Dockerfile
# Use a minimal base image
FROM python:3.9-slim
# Create a non-root user for security
RUN useradd -m user
USER user
# Set environment variables
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
PORT=7860
# Set the working directory
WORKDIR $HOME/app
# Copy requirements and install dependencies in a single RUN command
COPY --chown=user requirements.txt ./
RUN pip install --upgrade pip && \
pip install -r requirements.txt
# Copy application files and the model
COPY --chown=user ./ $HOME/app
# Expose the correct port for Hugging Face Spaces
EXPOSE 7860
# Run the FastAPI app with uvicorn directly for lightweight deployment
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]๐ Project Structure
.
โโโ app.py # FastAPI app with /encode endpoint
โโโ encoder.py # Model wrapper for MiniLM encoder
โโโ requirements.txt # All required Python libraries
โโโ Dockerfile # For deployment
โโโ README.md # Documentation๐งพ Requirements
fastapi
uvicorn
sentence-transformers
numpy๐ Use in Python
import requests
text = "What time is the meeting?"
response = requests.post("http://localhost:7860/encode", json={"text": text})
embedding = response.json()["embedding"]
print(embedding)๐ฉโ๐ป Maintainer
Inherited Games Studio ๐ง contact@inheritedgames.com ๐ github.com/inheritedgames ๐ github.com/RAMA012001
๐ License
MIT License
๐ Credits
- Model from: sentence-transformers/all-MiniLM-L6-v2
- API built with: FastAPI
- Hosting suggestion: Hugging Face Spaces
