Skip to content

KishoreB25/Slango

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

72 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Slango Slango

Where language meets intelligence.

FastAPI React Python Vite

Slango is a full-stack AI translation application supporting 15 languages with automatic language detection, real-time translation, and a modern glassmorphic UI β€” powered by Hugging Face Helsinki‑NLP models (no Google Cloud credentials required).

API Docs Β· Report Bug Β· Request Feature


✨ Features

Feature Description
πŸ” Auto Language Detection Detects the source language automatically β€” no manual selection needed
🌍 15 Languages Supported English, Spanish, French, German, Italian, Portuguese, Russian, Japanese, Korean, Chinese, Arabic, Hindi, Bengali, Tamil, Telugu
⚑ Async Translation Engine Non-blocking async API calls with configurable retry logic and linear backoff
πŸ›‘οΈ Rate Limiting Per-IP rate limiting (10 req / 60 s by default) to prevent abuse
πŸ“‹ Request Tracing Every request gets a unique ID with structured duration logging
πŸ”„ Fallback Mode Gracefully degrades when API credentials are unavailable (dev-friendly)
🩺 Health Endpoint /api/v1/health for uptime monitoring and deployment checks
πŸ“– Interactive API Docs Auto-generated Swagger UI at /docs and ReDoc at /redoc
🎨 Modern UI Glassmorphic React frontend built with Vite for near-instant HMR

🧰 Tech Stack

Backend

Technology Version Purpose
Python 3.11 Runtime
FastAPI 0.115 REST API framework
Uvicorn 0.30 ASGI server
Pydantic v2 2.9 Data validation & settings
pydantic-settings 2.5 .env-based config management
pydantic-core 2.23 Pinned for pre-built wheel compatibility
httpx 0.27 Async HTTP client
langdetect 1.0.9 Offline language detection fallback
Google Cloud Translate v2 Primary translation engine
huggingface_hub β‰₯0.25 HF Inference API + model downloads
pytest / pytest-asyncio β‰₯8.0 Test suite

Frontend

Technology Version Purpose
React 19 UI framework
Vite 8 Build tool & dev server
Axios 1.15 HTTP client
Vanilla CSS β€” Styling & animations

Infrastructure

Service Purpose
Render Backend hosting (Python 3.11, free tier)
Vercel / Netlify Frontend static hosting
Google Cloud Translation API (primary)
Hugging Face Alternative / extended translation models

πŸ€— Using Hugging Face Models (Optional)

Slango's service layer is designed to be swappable. Hugging Face translation models can replace or supplement Google Cloud Translate β€” ideal for offline inference, cost control, or unsupported language pairs.

Step 1 β€” Browse Models

Go to the Hugging Face Hub and filter by task:

https://huggingface.co/models?pipeline_tag=translation

Recommended models:

Model Languages Size
Helsinki-NLP/opus-mt-en-es English β†’ Spanish ~300 MB
Helsinki-NLP/opus-mt-en-fr English β†’ French ~300 MB
Helsinki-NLP/opus-mt-mul-en Multilingual β†’ English ~300 MB
facebook/nllb-200-distilled-600M 200 languages ~2.4 GB

Step 2 β€” Create a HF Access Token

  1. Create a free account at huggingface.co
  2. Go to Settings β†’ Access Tokens β†’ New Token
  3. Select Read access and copy the token

Step 3 β€” Configure the Environment

Add to your backend/.env:

HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
HF_MODEL_ID=Helsinki-NLP/opus-mt-en-es

Step 4 β€” Inference API (No GPU / No Download Required)

from huggingface_hub import InferenceClient

client = InferenceClient(token="hf_your_token_here")

result = client.translation(
    "Hello, how are you?",
    model="Helsinki-NLP/opus-mt-en-es"
)
print(result.translation_text)  # β†’ "Hola, ΒΏcΓ³mo estΓ‘s?"

The Inference API runs the model on Hugging Face's servers β€” no local GPU needed. Free tier supports most Helsinki-NLP models.

Step 5 β€” Local Inference (Advanced)

Install extra dependencies:

pip install transformers torch sentencepiece
from transformers import pipeline

translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
result = translator("Hello, how are you?")
print(result[0]["translation_text"])

Requirement: β‰₯ 4 GB RAM. Use the Inference API for lightweight/serverless deployments.


πŸš€ Getting Started

Prerequisites

  • Python 3.11+
  • Node.js 18+ and npm
  • Google Cloud project with Translation API enabled (or run in fallback mode without credentials)

1. Clone the Repository

git clone https://github.com/KishoreB25/CodeAlpha_Slango.git
cd CodeAlpha_Slango

2. Backend Setup

cd backend

# Create and activate a virtual environment
python -m venv venv

# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

3. Configure Environment Variables

cp .env.example .env

Edit backend/.env:

# ── App ───────────────────────────────────────────────────────
APP_NAME=Slango
APP_VERSION=1.0.0
APP_ENV=development
DEBUG=true

# ── Server ────────────────────────────────────────────────────
HOST=0.0.0.0
PORT=8000

# ── CORS ──────────────────────────────────────────────────────
# Comma-separated list of allowed frontend origins
ALLOWED_ORIGINS=http://localhost:5173

# ── Rate Limiting ─────────────────────────────────────────────
RATE_LIMIT_MAX_REQUESTS=10
RATE_LIMIT_WINDOW_SECONDS=60


# ── Hugging Face Inference API ──────────────────────────────────────────────────────
# Get your free token at: https://huggingface.co/settings/tokens
HF_API_TOKEN=hf_your_token_here
# Models are resolved dynamically by ModelResolver (Helsinki-NLP/opus-mt-*)
 
# ──Translation settings ──────────────────────────────────────────────────────
TRANSLATE_TIMEOUT_SECONDS=10
TRANSLATE_MAX_RETRIES=2
TRANSLATE_RETRY_DELAY_SECONDS=0.5

4. Run the Backend

uvicorn app.main:app --reload
Endpoint URL
Base API http://localhost:8000
Swagger UI http://localhost:8000/docs
ReDoc http://localhost:8000/redoc
Health http://localhost:8000/api/v1/health

5. Frontend Setup

cd ../frontend
npm install
npm run dev

Frontend: http://localhost:5173


πŸ“‘ API Reference

All endpoints are prefixed with /api/v1.

POST /api/v1/translate

Translate text between supported languages.

Request body:

{
  "text": "Hello, how are you?",
  "source_lang": "auto",
  "target_lang": "es"
}
Field Type Required Description
text string βœ… Text to translate (1–500 characters)
source_lang string βœ… ISO 639-1 code or "auto" for auto-detection
target_lang string βœ… ISO 639-1 target language code

Response:

{
  "translated_text": "Hola, ΒΏcΓ³mo estΓ‘s?",
  "source_lang": "en",
  "target_lang": "es"
}

Error codes:

Code Error Description
400 unsupported_language Invalid language code supplied
400 same_language Source and target languages are identical
429 rate_limit_exceeded Too many requests β€” see retry_after in response
502 translation_failed Service unavailable after all retries
504 translation_timeout Request exceeded timeout

GET /api/v1/languages

Returns all supported language codes.

Response:

{
  "languages": {
    "en": "English",
    "es": "Spanish",
    "fr": "French",
    "de": "German",
    "it": "Italian",
    "pt": "Portuguese",
    "ru": "Russian",
    "ja": "Japanese",
    "ko": "Korean",
    "zh": "Chinese (Simplified)",
    "ar": "Arabic",
    "hi": "Hindi",
    "bn": "Bengali",
    "ta": "Tamil",
    "te": "Telugu"
  },
  "count": 15
}

GET /api/v1/health

Health check for uptime monitoring.

Response:

{
  "status": "healthy",
  "version": "1.0.0",
  "timestamp": "2026-07-06T00:00:00+00:00"
}

πŸ“ Project Structure

CodeAlpha_Slango/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   └── routes/
β”‚   β”‚   β”‚       └── translate.py      # /translate, /health, /languages
β”‚   β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”‚   β”œβ”€β”€ config.py             # Pydantic settings (loads .env)
β”‚   β”‚   β”‚   └── logging.py            # Structured logger
β”‚   β”‚   β”œβ”€β”€ schemas/
β”‚   β”‚   β”‚   └── translation.py        # Request / response models
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ base.py               # Abstract TranslatorService
β”‚   β”‚   β”‚   └── google_translate.py   # Google Cloud Translate v2
β”‚   β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”‚   └── rate_limiter.py       # Per-IP in-memory rate limiter
β”‚   β”‚   └── main.py                   # App, middleware, lifespan
β”‚   β”œβ”€β”€ tests/                        # pytest test suite
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ runtime.txt                   # Pins Python 3.11.9 (for Render)
β”‚   └── .env.example
β”‚
└── frontend/
    β”œβ”€β”€ src/                          # React components & pages
    β”œβ”€β”€ public/
    β”œβ”€β”€ index.html
    β”œβ”€β”€ vite.config.js
    └── package.json

πŸ§ͺ Testing

cd backend
# With venv active
pytest

# Verbose output
pytest -v

# Specific file
pytest tests/test_translate.py -v

πŸ”’ Security

  • API credentials are never logged - only metadata (text length, language codes) is recorded
  • User input is never stored server-side
  • CORS is scoped to explicitly configured origins only
  • Per-IP rate limiting guards against abuse

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feat/your-feature
  3. Commit your changes using Conventional Commits: git commit -m "feat: add xyz"
  4. Push and open a Pull Request

About

An AI-powered translation tool built with FastAPI & React. Uses Helsinki-NLP OPUS-MT models via the Hugging Face Inference API to translate across 15 languages, with automatic language detection, rate limiting, and a modern dark-mode UI.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages