Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A FastAPI-based NER API for detecting bank names using spaCy. Includes customizable patterns, Dockerized for easy deployment, and ready for cloud hosting.

kishore-144/bank-ner

Repository files navigation

Bank NER API

A FastAPI-based Named Entity Recognition (NER) API for detecting bank names using spaCy. The API supports customizable patterns, is Dockerized for easy deployment, and ready for cloud hosting.


Features

  • Detects bank names in text using spaCy's EntityRuler.
  • Allows adding custom patterns dynamically via the /train/ endpoint.
  • Fast and lightweight using FastAPI.
  • Dockerized for portability and easy deployment.
  • CORS enabled for frontend integration.

Project Structure

bank-ner/
├── bank_patterns.json       # JSON file with default bank patterns
├── main.py                  # FastAPI application
├── requirements.txt         # Python dependencies
├── Dockerfile               # Docker configuration
└── __pycache__/             # Compiled Python files

Installation

1. Clone the repository

git clone https://github.com/kishore-144/bank-ner.git

2. Create virtual environment (optional)

python3 -m venv venv
source venv/bin/activate  # Linux/macOS
venv\Scripts\activate     # Windows

3. Install dependencies

pip install -r requirements.txt

4. Run locally

uvicorn main:app --reload --host 0.0.0.0 --port 8000

Open http://localhost:8000/docs for the interactive API documentation.


API Endpoints

1. Train new patterns

  • Endpoint: /train/
  • Method: POST
  • Body:
{
  "l1": [
    {
      "label": "BANK",
      "pattern": "UAB"
    },
    {
      "label": "BANK",
      "pattern": "IDBI"
    }
  ]
}
  • Response:
{"message": "2 patterns added"}

2. Test sentence

  • Endpoint: /test/
  • Method: POST
  • Body:
{
  "sentence": "I have accounts in SBI and HDFC Bank."
}
  • Response:
[
  ["SBI", "BANK"],
  ["HDFC Bank", "BANK"]
]

Docker

1. Build Docker image

docker build -t bank-ner-api .

2. Run container

docker run -d -p 8000:8000 bank-ner-api

3. Stop and remove container

docker ps                       # Get container ID
docker stop <container_id>
docker rm <container_id>

Deployment

  • The app can be deployed to Azure App Service, AWS ECS, Google Cloud Run, or any other container-hosting service.
  • Ensure the Docker image exposes port 8000 and the container is set to run uvicorn main:app --host 0.0.0.0 --port 8000.

Requirements

  • Python 3.11+
  • FastAPI
  • spaCy
  • Docker (optional, for containerization)

Contributing

  1. Fork the repo
  2. Create a new branch (git checkout -b feature/xyz)
  3. Make your changes
  4. Commit (git commit -m 'Add feature xyz')
  5. Push (git push origin feature/xyz)
  6. Open a pull request

License

This project is licensed under the MIT License.


Author

Kishore Passionate about machine learning, web development, and building scalable APIs.


About

A FastAPI-based NER API for detecting bank names using spaCy. Includes customizable patterns, Dockerized for easy deployment, and ready for cloud hosting.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published