File size: 3,492 Bytes
642914f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# LUT Transformation API
A FastAPI-based service for transforming .cube LUT files using AI-generated color adjustments and creating split preview images.
## Features
- **LUT Transformation**: Transform .cube files using JSON-based color adjustments
- **AI Integration**: Generate color adjustments based on natural language prompts
- **Split Preview**: Create side-by-side comparison images showing before/after effects
- **Base64 Support**: Handle file uploads and image responses in base64 format
## Setup
### 1. Install Dependencies
```bash
pip install -r requirements.txt
```
### 2. Run the Server
```bash
uvicorn main:app --reload
```
The API will be available at `http://localhost:8000`
### 3. API Documentation
Visit `http://localhost:8000/docs` for interactive API documentation.
## API Endpoints
### POST /transform-lut
Transform a LUT file using a text prompt.
**Request Body:**
```json
{
"cube_file_base64": "base64_encoded_cube_file",
"user_prompt": "Make this LUT more cinematic with cool shadows"
}
```
**Response:**
```json
{
"success": true,
"message": "LUT transformation completed successfully",
"adjustments_applied": {
"shadows": {"r": 0.9, "g": 1.0, "b": 1.2},
"midtones": {"r": 1.0, "g": 1.0, "b": 1.0},
"highlights": {"r": 1.1, "g": 1.05, "b": 0.95},
"global": {"r": 1.0, "g": 1.0, "b": 1.0}
},
"split_preview_base64": "base64_encoded_preview_image"
}
```
### GET /health
Check API health and sample image availability.
**Response:**
```json
{
"status": "healthy",
"sample_image_exists": true
}
```
## How It Works
1. **Upload**: Send a .cube file as base64 and a text prompt
2. **AI Processing**: The `generate_new_cube()` function processes the prompt and returns JSON adjustments
3. **LUT Transformation**: Apply the adjustments to the original LUT using the `LUTTransformer` class
4. **Image Processing**: Apply both original and modified LUTs to the sample image
5. **Split Preview**: Create a side-by-side comparison with a vertical divider line
6. **Response**: Return the preview image as base64
## LUT Adjustment Format
The AI generates adjustments in this JSON format:
```json
{
"shadows": {"r": 0.9, "g": 1.0, "b": 1.2},
"midtones": {"r": 1.0, "g": 1.0, "b": 1.0},
"highlights": {"r": 1.1, "g": 1.05, "b": 0.95},
"global": {"r": 1.0, "g": 1.0, "b": 1.0}
}
```
- **shadows**: Adjustments for darker regions (luminance < 0.33)
- **midtones**: Adjustments for medium regions (0.33 ≤ luminance < 0.66)
- **highlights**: Adjustments for brighter regions (luminance ≥ 0.66)
- **global**: Overall adjustments applied to all regions
## Testing
Use the provided `test_main.http` file to test the endpoints, or use curl:
```bash
curl -X POST "http://localhost:8000/transform-lut" \
-H "Content-Type: application/json" \
-d '{
"cube_file_base64": "VElUTEUgIlRlc3QgTFVUIgpMVVRfM0RfU0laRSAyCg...",
"user_prompt": "Make this LUT more cinematic with cool shadows"
}'
```
## Sample Image
The API uses `sample.jpg` as the standard test image for preview generation. Make sure this file exists in the project root.
## AI Integration
Replace the placeholder `generate_new_cube()` function with your actual AI implementation that takes a user prompt and returns color adjustment JSON.
## Error Handling
The API includes comprehensive error handling for:
- Invalid cube file formats
- Missing sample images
- Base64 decoding errors
- Image processing failures
- File system operations |