A production-ready deep learning application that classifies images as cats or dogs with ~92% accuracy.
Deployed with Railway (backend) and Streamlit Cloud (frontend) for seamless access worldwide.
- π¨ Web Application: https://cat-dog-prediction.streamlit.app/
- π API Backend: https://web-production-c142d.up.railway.app/
- π API Documentation: https://web-production-c142d.up.railway.app/docs
- β¨ Features
- π¬ Demo
- π Quick Start
- π‘ API Documentation
- π‘ Usage Examples
- ποΈ Architecture
- π Project Structure
- π’ Deployment
- π Troubleshooting
- π€ Contributing
| Feature | Web App (Streamlit) | REST API (FastAPI) |
|---|---|---|
| User Interface | β Interactive web UI | β API only (integrate with your app) |
| Real-time Classification | β Instant visual results | β JSON response |
| Batch Processing | β One image at a time | β Up to 10 images per request |
| Integration | β Standalone app | β Any language/platform |
| Auto Documentation | β N/A | β Swagger UI + ReDoc |
| Mobile Friendly | β Responsive design | β Mobile apps can integrate |
| Cloud Deployment | β Streamlit Cloud | β Railway |
| Best For | End-users, demos | Developers, production systems |
- πΌοΈ Modern UI with gradient animations and smooth transitions
- π― Drag-and-drop image upload with instant preview
- π Confidence meters with visual progress bars
- π± Mobile responsive design that works everywhere
- β‘ Auto model download from Google Drive (111 MB, cached)
- π Fast inference ~100-300ms per image
- π¨ Animated result cards color-coded by prediction
- π Detailed metrics expandable technical information
- π RESTful endpoints following industry best practices
- π¦ Batch prediction process up to 10 images in one request
- π CORS enabled ready for web and mobile apps
- β Input validation file type, size, and format checks
- π Health checks monitor API and model status
- π‘οΈ Production-ready with comprehensive logging
- π Interactive docs Swagger UI at
/docsand ReDoc at/redoc - β‘ Async support high-performance with uvicorn
- π Detailed responses confidence scores, probabilities, metadata
Try it live: https://cat-dog-prediction.streamlit.app/
Upload any cat or dog image and get instant AI predictions!
{
"success": true,
"filename": "cat.jpg",
"prediction": "Cat",
"confidence_percentage": 98.5,
"probabilities": {
"cat": 98.5,
"dog": 1.5
}
}- β Python 3.8+ (Download)
- β pip package manager
- β Git (Download)
- β Internet connection (for model download)
1. Clone Repository
git clone https://github.com/fsRakib/Image-Classification-CNN.git
cd Image-Classification-CNN2. Create Virtual Environment
# Windows
python -m venv venv
.\venv\Scripts\Activate.ps1
# Linux/Mac
python -m venv venv
source venv/bin/activate3. Install Dependencies
pip install -r requirements.txt4. Run Backend API
uvicorn api:app --host 0.0.0.0 --port 8000 --reloadAccess at: http://localhost:8000
5. Run Streamlit Frontend (Optional)
streamlit run streamlit_app.pyAccess at: http://localhost:8501
| Endpoint | Method | Description |
|---|---|---|
| / | GET | API information |
| /health | GET | Health check |
| /model/info | GET | Model details |
| /predict | POST | Single image prediction |
| /predict/batch | POST | Batch predictions (up to 10) |
curl -X POST "https://web-production-c142d.up.railway.app/predict" -F "file=@cat.jpg"Response:
{
"success": true,
"prediction": "Cat",
"confidence_percentage": 98.5,
"probabilities": { "cat": 98.5, "dog": 1.5 }
}import requests
url = "https://web-production-c142d.up.railway.app/predict"
with open("cat.jpg", "rb") as f:
response = requests.post(url, files={"file": f})
print(response.json())const formData = new FormData();
formData.append("file", fileInput.files[0]);
fetch("https://web-production-c142d.up.railway.app/predict", {
method: "POST",
body: formData
})
.then(res => res.json())
.then(data => console.log(data));User β Streamlit Cloud (UI) β Railway.app (API) β CNN Model β Prediction
- Architecture: Convolutional Neural Network (CNN)
- Framework: TensorFlow/Keras
- Input: 128Γ128Γ3 RGB images
- Accuracy: ~92%
- Model Size: 111 MB
- Dataset: 25,000 cat/dog images
Image-Classification-CNN/
βββ api.py # FastAPI backend
βββ streamlit_app.py # Streamlit frontend
βββ api_client.py # API client wrapper
βββ requirements.txt # Dependencies
βββ Procfile # Railway config
βββ railway.json # Railway build settings
βββ dogs_vs_cats_production_model.keras # Model (111 MB)
βββ README.md # Documentation
- Backend: Railway.app (Auto-deploy from main branch)
- Frontend: Streamlit Cloud (Auto-deploy from main branch)
Backend to Railway:
- Fork repository
- Sign up on Railway.app
- New project β Deploy from GitHub
- Select repository (auto-detects config)
Frontend to Streamlit Cloud:
- Sign up on Streamlit.io/cloud
- New app β Select repository
- Main file: streamlit_app.py
- Add secret:
API_BASE_URL = "your-railway-url"
Model Download Fails
- Check internet connection
- Download manually: [Google Drive Link]
- Place in project root
API Connection Error
- Verify Railway backend is running
- Check Streamlit secrets configuration
- Test:
curl https://your-url/health
Module Not Found
- Activate virtual environment
- Run:
pip install -r requirements.txt
Port Already in Use
- Use different port:
uvicorn api:app --port 8001 - Or kill process:
netstat -ano | findstr :8000
Contributions welcome! Please:
- Fork the repository
- Create feature branch
- Make changes
- Test thoroughly
- Submit pull request
MIT License - see LICENSE file
- Kaggle Dogs vs Cats dataset
- TensorFlow & Keras teams
- FastAPI & Streamlit teams
- Railway & Streamlit Cloud
- Model Size: 111 MB
- Training Images: 25,000
- Accuracy: ~92%
- Inference Time: 100-300ms
- Supported Formats: JPG, JPEG, PNG
- Max File Size: 10MB
Developer: Fahim Shahriar Rakib
- GitHub: @fsRakib
- Project: Image-Classification-CNN
- Live Demo: cat-dog-prediction.streamlit.app
Made with β€οΈ using TensorFlow, FastAPI, and Streamlit
β Star this repo if you found it helpful!