An end-to-end AI application that detects whether a text message indicates an emergency.
This project combines Natural Language Processing (NLP), a deep learning model, and a full-stack system with database and deployment.
Users can:
- Enter a message
- Get an AI prediction (Emergency / Not Emergency)
- View message history stored in a database
The entire system is fully containerized and can be run locally with a single command.
-
User enters a message in the frontend (Next.js UI)
-
Frontend sends request to backend: POST /predict
-
Backend processes text:
- Cleans text (lowercase, remove symbols, URLs, etc.)
- Tokenizes into words
- Converts words to numerical indices using a vocabulary
- Pads or truncates to fixed length
- Model prediction:
- Bidirectional LSTM processes the sequence
- Outputs logits → converted into prediction (emergency / not emergency)
- Database storage:
- Message and prediction are saved into PostgreSQL
- Response:
- Result is returned and displayed to user
- History retrieval: GET /history
- Fetches latest messages from database
Backend:
- FastAPI
- PyTorch (BiLSTM model)
- psycopg2
Frontend:
- Next.js (React)
- TailwindCSS
Database:
- PostgreSQL
DevOps / Deployment:
- Docker
- Docker Compose
- AWS EC2
- GitHub Actions (CI/CD)
disaster_classification/ │ ├── backend/ │ ├── src/ │ │ ├── api.py │ │ ├── model.py │ │ ├── inference.py │ │ └── dataset.py │ ├── Dockerfile │ └── requirements.txt │ ├── frontend/ │ ├── app/ │ ├── Dockerfile │ └── package.json │ ├── docker-compose.yml └── README.md
- Docker
- Docker Compose
git clone https://github.com/moecrosoft/disaster_classification.git cd disaster_classification
docker-compose up -d --build
This will start:
- Frontend → http://localhost:3000
- Backend → http://localhost:8000
- PostgreSQL database
docker-compose down
- Architecture: Bidirectional LSTM
- Embedding size: 128
- Hidden size: 128
- Sequence length: 60
- Output: 2 classes (Emergency / Not Emergency)
Training Features:
- Text cleaning and normalization
- Vocabulary with and
- Rare word filtering (min_freq)
- Class imbalance handling:
- Weighted loss
- WeightedRandomSampler
Evaluation Metrics:
- Accuracy
- F1 Score (~0.72 on validation set)
- Real-time AI prediction
- Message history tracking
- Color-coded results:
- 🔴 Emergency
- 🟢 Not Emergency
- Fully containerized system
- One-command local deployment
This project is deployed on AWS EC2 using:
- Docker Compose for container orchestration
- GitHub Actions for automatic deployment on push to main
Deployment workflow:
- Push to GitHub
- GitHub Actions SSH into EC2
- Pull latest code
- Build Docker containers
- Restart services
POST /predict
Request: { "text": "Someone collapsed and needs help" }
Response: { "prediction": "emergency (confidence: 0.91)" }
GET /history
Response: [ { "user_message": "...", "ai_result": "..." } ]