File size: 1,497 Bytes
235461a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Img Edit Agent API
emoji: πŸ–ΌοΈ
colorFrom: indigo
colorTo: blue
sdk: docker
app_port: 7860
pinned: false
---

# AI Image Editor API

FastAPI service powering the Img Edit Agent web app. It provides chat-driven image editing and generation.

## Features

- **POST `/chat`** – Send a message and optional image metadata; receives an AI reply with optional generated image details.
- **GET `/health`** – Reports service and database status.
- **Rate limiting & startup hooks** – Initializes a rate-limit table on startup and logs shutdown events.
- **Modular LLM tools** – Uses the `llm` package for agent logic, database connections, and utilities.

## Project Structure

```
api/
β”œβ”€β”€ server/         # FastAPI application
β”œβ”€β”€ llm/            # LLM agent and helpers
β”œβ”€β”€ tests/          # pytest suite
β”œβ”€β”€ Dockerfile      # Container build
└── README.md
```

## Running Locally

```bash
pip install -e .[dev]
uvicorn server.main:app --host 0.0.0.0 --port 8000
```

## API Reference

### POST `/chat`

Request body:

```json
{
  "message": "Describe edit",
  "selected_images": [{ "id": "...", "url": "..." }],
  "user_id": "optional"
}
```

Response:

```json
{
  "response": "AI response",
  "status": "success",
  "generated_image": { "id": "...", "url": "..." }
}
```

### GET `/health`

Returns service and database status.

## Deployment

This API is built to run as a Docker container on [Hugging Face Spaces](https://huggingface.co/spaces).