Vision AI Flask Application Deployment Guide
Table of Contents
Introduction
This guide provides step-by-step instructions for deploying the Vision AI Flask application. The application provides AI-powered image generation capabilities through a REST API.
Prerequisites
- Python 3.8+
- Git
- Google Cloud account with Vertex AI enabled
- Linux server (Ubuntu 20.04 recommended)
- Domain name with DNS configured
- GitHub repository access
Installation
- Clone the repository:
git clone https://github.com/Eh-Mr-SK/vision-ai-flask.git cd vision-ai-flask - Create and activate virtual environment:
python3 -m venv venv source venv/bin/activate - Install dependencies:
pip install -r requirements.txt
Configuration
- Create
.envfile:cp .env.example .env - Edit
.envwith your credentials:API_SECRET_KEY=your-secure-api-key GITHUB_SECRET=your-github-webhook-secret - Set up Google Cloud credentials:
export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/service-account.json" - Create storage directory:
mkdir -p storage/images
Deployment
- Install Gunicorn:
pip install gunicorn - Set up SSL certificates using Let’s Encrypt:
sudo apt install certbot python3-certbot-nginx sudo certbot certonly --standalone -d yourdomain.com - Create systemd service file
/etc/systemd/system/visionai.service:[Unit] Description=Vision AI Flask Application After=network.target [Service] User=www-data Group=www-data WorkingDirectory=/path/to/vision-ai-flask ExecStart=/path/to/vision-ai-flask/venv/bin/gunicorn --workers 3 --bind 0.0.0.0:8000 --certfile /etc/letsencrypt/live/yourdomain.com/fullchain.pem --keyfile /etc/letsencrypt/live/yourdomain.com/privkey.pem main:app Restart=always [Install] WantedBy=multi-user.target - Start and enable the service:
sudo systemctl daemon-reload sudo systemctl start visionai sudo systemctl enable visionai
CI/CD Setup
- In your GitHub repository, go to Settings > Webhooks
- Add new webhook:
- Payload URL:
https://yourdomain.com/github-webhook - Content type:
application/json - Secret: Use the same secret as in
.env - Events: Select “Just the push event”
- Payload URL:
- Save the webhook
Maintenance
- View logs:
sudo journalctl -u visionai -f - Restart service:
sudo systemctl restart visionai - Update application:
git pull origin main sudo systemctl restart visionai
Troubleshooting
- API not responding:
- Check service status:
sudo systemctl status visionai - Check logs:
sudo journalctl -u visionai
- Check service status:
- Image generation failing:
- Verify Google Cloud credentials
- Check Vertex AI quota and permissions
- GitHub webhook not working:
- Verify webhook secret matches
.env - Check GitHub webhook delivery logs
- Verify webhook secret matches
- SSL certificate issues:
- Renew certificates:
sudo certbot renew - Verify certificate paths in service fil
- Renew certificates:
