FastAPI microservice that detects whether input text is English and, if needed, translates it to English using an Ollama chat model.
- Endpoint:
GET / - Query param:
content(string) - Response shape:
{
"is_english": false,
"translated_content": "This is a German message"
}Example:
curl "http://127.0.0.1:5001/?content=Dies%20ist%20eine%20Nachricht%20auf%20Deutsch"python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtpytestuvicorn app:app --host 0.0.0.0 --port 5001Then open:
http://127.0.0.1:5001/?content=Hellohttp://127.0.0.1:5001/?content=Hola%20mundo
The repository includes docker-compose.yml with:
translatorservice on port5001ollamaservice for model inference
Run:
docker compose up --build -d
docker compose exec -T ollama ollama pull qwen3:0.6bEnvironment variables used by src/translator.py:
OLLAMA_HOST(default:http://127.0.0.1:11434)OLLAMA_MODEL(default:qwen3:0.6b)OLLAMA_TIMEOUT_CONNECT(default:5.0)OLLAMA_TIMEOUT_READ(default:90.0)
In Docker Compose, OLLAMA_HOST is set to http://ollama:11434.
GitHub Actions workflow at .github/workflows/deploy.yml deploys to your VM over SSH on pushes to main, then runs:
docker compose down
docker compose up --build -d
docker compose exec -T ollama ollama pull qwen3:0.6b