# Gallery Extension

The Gallery extension intercepts all generated image, audio & file assets and uploaded files in `~/.llms/cache` file storage whose metadata is maintained in a SQLite database.

Dedicated UIs are available for quickly browsing and navigating or generated images / audio files with optimized UIs for viewing portrait, square and landscape images.

## Generated Asset Interception

The Gallery extension automatically monitors the creation of new cache entries. Whenever a file is saved to the LLMs cache (located at `~/.llms/cache`), the extension captures its metadata and stores it in the gallery database.

This includes:
- **Generated Images**: Images created by AI models (e.g., DALL-E, Stable Diffusion).
- **Generated Audio**: Audio files generated by text-to-speech or audio models.
- **Uploaded Files**: Any files uploaded through the UI.

All metadata is stored in a dedicated SQLite database located at `~/.llms/user/default/gallery/gallery.sqlite`, in the `media` table.

## User Interface

The Gallery UI provides a rich, interactive way to explore your generated assets. You can access it via the **Gallery** tab in the sidebar or by navigating to `/gallery`.

### Image Gallery

The image view offers a responsive grid layout optimized for different aspect ratios.

- **Filtering**:
    - **By Format**: Easily switch between **Portrait**, **Square**, and **Landscape** views to see images in their best light.
    - **Search**: Real-time search by prompt, model name, or other metadata.
- **Interactions**:
    - **Lightbox**: Click any image to view it in full screen.
    - **Details**: View comprehensive metadata including the prompt used, generation model, dimensions, file size, creation date, and generation cost.
    - **Download**: extensive download options.
    - **Remix**: Quickly re-use the prompt and settings of an existing image to generate a new one.
    - **Delete**: Remove unwanted images from the gallery.

### Audio Gallery

The audio view presents a list layout designed for easy listening and management.

- **Playback**: Integrated audio player to preview generated sounds directly in the list.
- **Metadata**: Displays the caption/prompt, model, and creation time.
- **Actions**:
    - **Remix**: Regenerate audio using the same prompt.
    - **Delete**: Remove audio files.

## Storage Data model

The `media` table tracks extensive information about each asset to support the search and filtering capabilities:

| Column | Description |
|---|---|
| `url` | Relative path to the file in `~/.llms/cache` |
| `type` | Asset type (image, audio, video) |
| `prompt` | The prompt used to generate the asset |
| `model` | The AI model used |
| `aspect_ratio` | Aspect ratio (e.g., "1:1", "16:9") |
| `cost` | Generation cost |
| `metadata` | Additional JSON metadata |
| `created` | Timestamp of creation |

This local database ensures your gallery remains fast and responsive, even with a large collection of generated assets.
