# AI Event Photo Delivery System

This project is a Flask backend that stores user and event images in AWS S3, indexes user faces with Amazon Rekognition, matches event photos against the face collection, and sends a single grouped email per user.

## Environment Variables

Create a `.env` file with your company AWS account values:

```env
AWS_ACCESS_KEY_ID=YOUR_NEW_KEY
AWS_SECRET_ACCESS_KEY=YOUR_NEW_SECRET
AWS_REGION=us-east-1

S3_BUCKET=YOUR_NEW_BUCKET_NAME
COLLECTION_ID=YOUR_NEW_COLLECTION_ID

DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_NAME=event_ai

SMTP_HOST=your_smtp_host
SMTP_PORT=587
SMTP_USER=your_smtp_user
SMTP_PASSWORD=your_smtp_password
SENDER_EMAIL=your_sender_email
```

## AWS Configuration

All AWS access is centralized in [config/aws_config.py](/C:/Users/Newpassword/PyCharmMiscProject/event-photo-delivery/config/aws_config.py).

- `get_aws_settings()` validates environment variables
- `get_boto3_session()` creates the shared boto3 session
- `get_s3_client()` returns the shared S3 client
- `get_rekognition_client()` returns the shared Rekognition client

No AWS credentials, bucket names, or Rekognition collection IDs should be hardcoded in application code.

## Install Dependencies

```bash
pip install -r requirements.txt
```

## Run Flask App

```bash
python app.py
```

## Run Matching Scripts

```bash
python scripts/run_event_matching.py
python scripts/run_full_pipeline.py
```

## Important Safety Rules Implemented

- Original uploads and processed uploads are stored separately in S3
- Processed images are used for Rekognition matching
- Original image URLs are used in email delivery
- Rekognition collection existence is checked automatically
- AWS calls include error handling and logging
- One email is sent per user for the current matched batch
- Images already delivered are not emailed again
