A robust backend API for a translation application, built with FastAPI, PostgreSQL, and Hugging Face Inference API.
- Authentication: Secure user registration and login using JWT (JSON Web Tokens).
- Translation: Translate text between English and French using state-of-the-art models hosted on Hugging Face.
- French to English (
Helsinki-NLP/opus-mt-fr-en) - English to French (
Helsinki-NLP/opus-mt-en-fr)
- French to English (
- Database: PostgreSQL integration with SQLAlchemy ORM.
- Security: Password hashing with Bcrypt, environment variable configuration.
- Framework: FastAPI
- Database: PostgreSQL
- ORM: SQLAlchemy
- Authentication: Python-Jose, Passlib (Bcrypt)
- AI/ML: Hugging Face Inference API
-
Clone the repository:
git clone https://github.com/Ysen0603/Translator_backend.git cd Translator_backend -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure Environment Variables: Create a
.envfile in the root directory and add the following:DATABASE_URL=postgresql://user:password@localhost/dbname SECRET_KEY=your_secure_secret_key HUGGINGFACE_API_KEY=your_huggingface_api_key
-
Run the application:
uvicorn main:app --reload
Once the server is running, you can access the interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
POST /api/v1/auth/register: Register a new user.POST /api/v1/auth/login: Login and get an access token.
POST /api/v1/translation/: Translate text (Requires Authentication).- Body:
{"text": "Hello", "source_lang": "en", "target_lang": "fr"}
- Body: