bria-vgl 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bria_vgl-0.1.0/.gitignore +200 -0
- bria_vgl-0.1.0/LICENSE +21 -0
- bria_vgl-0.1.0/PKG-INFO +151 -0
- bria_vgl-0.1.0/README.md +112 -0
- bria_vgl-0.1.0/pyproject.toml +125 -0
- bria_vgl-0.1.0/src/vgl/__init__.py +9 -0
- bria_vgl-0.1.0/src/vgl/_version.py +6 -0
- bria_vgl-0.1.0/src/vgl/api.py +58 -0
- bria_vgl-0.1.0/src/vgl/dialects/__init__.py +5 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/__init__.py +6 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/input_schema/edit.txt +44 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/input_schema/edit_multi_ref.txt +44 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/input_schema/generate.txt +43 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/input_schema/inpaint.txt +44 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/model.py +9 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/output_schema/edit.json +214 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/output_schema/generate.json +210 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/payloads.py +93 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_image/final_prompt.txt +6 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_image/system_prompt.txt +46 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_image_input_vgl/final_prompt.txt +9 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_image_input_vgl/system_prompt.txt +52 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_image_mask/final_prompt.txt +6 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_image_mask/system_prompt.txt +31 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_image_mask_input_vgl/final_prompt.txt +9 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_image_mask_input_vgl/system_prompt.txt +37 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_multi_images/final_prompt.txt +5 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_multi_images/system_prompt.txt +32 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_multi_images_input_vgl/final_prompt.txt +8 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/edit_multi_images_input_vgl/system_prompt.txt +38 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/generate/final_prompt.txt +1 -0
- bria_vgl-0.1.0/src/vgl/dialects/thales/prompts/generate/system_prompt.txt +25 -0
- bria_vgl-0.1.0/src/vgl/exceptions.py +37 -0
- bria_vgl-0.1.0/src/vgl/gateway.py +218 -0
- bria_vgl-0.1.0/src/vgl/model.py +64 -0
- bria_vgl-0.1.0/src/vgl/payload.py +60 -0
- bria_vgl-0.1.0/src/vgl/prompting.py +89 -0
- bria_vgl-0.1.0/src/vgl/py.typed +0 -0
- bria_vgl-0.1.0/src/vgl/utils/__init__.py +1 -0
- bria_vgl-0.1.0/src/vgl/utils/images.py +26 -0
- bria_vgl-0.1.0/src/vgl/utils/labels.py +34 -0
- bria_vgl-0.1.0/src/vgl/utils/vertex.py +40 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
|
|
110
|
+
# pdm
|
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
|
+
#pdm.lock
|
|
113
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
114
|
+
# in version control.
|
|
115
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
116
|
+
.pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
121
|
+
__pypackages__/
|
|
122
|
+
|
|
123
|
+
# Celery stuff
|
|
124
|
+
celerybeat-schedule
|
|
125
|
+
celerybeat.pid
|
|
126
|
+
|
|
127
|
+
# SageMath parsed files
|
|
128
|
+
*.sage.py
|
|
129
|
+
|
|
130
|
+
# Environments
|
|
131
|
+
.env
|
|
132
|
+
.venv
|
|
133
|
+
env/
|
|
134
|
+
venv/
|
|
135
|
+
ENV/
|
|
136
|
+
env.bak/
|
|
137
|
+
venv.bak/
|
|
138
|
+
|
|
139
|
+
# Spyder project settings
|
|
140
|
+
.spyderproject
|
|
141
|
+
.spyproject
|
|
142
|
+
|
|
143
|
+
# Rope project settings
|
|
144
|
+
.ropeproject
|
|
145
|
+
|
|
146
|
+
# mkdocs documentation
|
|
147
|
+
/site
|
|
148
|
+
|
|
149
|
+
# mypy
|
|
150
|
+
.mypy_cache/
|
|
151
|
+
.dmypy.json
|
|
152
|
+
dmypy.json
|
|
153
|
+
|
|
154
|
+
# Pyre type checker
|
|
155
|
+
.pyre/
|
|
156
|
+
|
|
157
|
+
# pytype static type analyzer
|
|
158
|
+
.pytype/
|
|
159
|
+
|
|
160
|
+
# Cython debug symbols
|
|
161
|
+
cython_debug/
|
|
162
|
+
|
|
163
|
+
# PyCharm
|
|
164
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
165
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
166
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
167
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
168
|
+
.idea/
|
|
169
|
+
|
|
170
|
+
# Abstra
|
|
171
|
+
# Abstra is an AI-powered process automation framework.
|
|
172
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
173
|
+
# Learn more at https://abstra.io/docs
|
|
174
|
+
.abstra/
|
|
175
|
+
|
|
176
|
+
# Visual Studio Code
|
|
177
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
178
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
179
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
180
|
+
# you could uncomment the following to ignore the enitre vscode folder
|
|
181
|
+
.vscode/
|
|
182
|
+
|
|
183
|
+
# Ruff stuff:
|
|
184
|
+
.ruff_cache/
|
|
185
|
+
|
|
186
|
+
# PyPI configuration file
|
|
187
|
+
.pypirc
|
|
188
|
+
|
|
189
|
+
# Cursor
|
|
190
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
191
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
192
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
193
|
+
.cursorignore
|
|
194
|
+
.cursorindexingignore
|
|
195
|
+
|
|
196
|
+
vertex_ai_creds.json
|
|
197
|
+
|
|
198
|
+
local_data/
|
|
199
|
+
# scratch tree written by examples/styles_examples/develop_a_style.py
|
|
200
|
+
.vgl-style-dev/
|
bria_vgl-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 BRIA AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
bria_vgl-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: bria-vgl
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Turn a prompt, or images plus a prompt, into a structured JSON scene description (VGL) for image models like FIBO.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Bria-AI/vgl
|
|
6
|
+
Project-URL: Documentation, https://github.com/Bria-AI/vgl#readme
|
|
7
|
+
Project-URL: Issues, https://github.com/Bria-AI/vgl/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Bria-AI/vgl/blob/dev/CHANGELOG.md
|
|
9
|
+
Author: Bria AI
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: bria,fibo,image generation,llm,prompt,structured output,vgl
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: boltons>=20.0.0
|
|
26
|
+
Requires-Dist: litellm>=1.80.11
|
|
27
|
+
Requires-Dist: openai>=2.20.0
|
|
28
|
+
Requires-Dist: pillow>=9.1.0
|
|
29
|
+
Requires-Dist: pydantic>=2.0
|
|
30
|
+
Requires-Dist: pyyaml>=6.0.1
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Requires-Dist: boto3>=1.34; extra == 'all'
|
|
33
|
+
Requires-Dist: google-auth>=2.0; extra == 'all'
|
|
34
|
+
Provides-Extra: bedrock
|
|
35
|
+
Requires-Dist: boto3>=1.34; extra == 'bedrock'
|
|
36
|
+
Provides-Extra: vertex
|
|
37
|
+
Requires-Dist: google-auth>=2.0; extra == 'vertex'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# VGL — Visual Generation Language
|
|
41
|
+
|
|
42
|
+
VGL turns a text prompt, or images plus a prompt, into a structured JSON description of a scene: objects, background, lighting, aesthetics, camera, and text. The result is a typed Pydantic model that an image model like FIBO takes as its prompt.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install bria-vgl
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The default LLM is Gemini through Google AI Studio. For other providers, install the extra:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install 'bria-vgl[vertex]' # Gemini on Vertex AI
|
|
54
|
+
pip install 'bria-vgl[bedrock]' # Claude on AWS Bedrock
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Authenticate
|
|
58
|
+
|
|
59
|
+
| Provider | `llm=` | Set |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| Google AI Studio (default) | `gemini/gemini-3.5-flash-lite` | `GEMINI_API_KEY` ([get one](https://aistudio.google.com/apikey)) |
|
|
62
|
+
| Vertex AI | `vertex_ai/gemini-3.5-flash-lite` | `VERTEXAI_PROJECT`, `VERTEXAI_LOCATION`, `GOOGLE_APPLICATION_CREDENTIALS` (a service account JSON) |
|
|
63
|
+
| AWS Bedrock | e.g. `bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0` | the usual AWS credentials and `AWS_REGION_NAME` |
|
|
64
|
+
|
|
65
|
+
`llm` takes any [litellm model id](https://docs.litellm.ai/docs/providers), but the prompts are tuned for Gemini.
|
|
66
|
+
|
|
67
|
+
## Quickstart
|
|
68
|
+
|
|
69
|
+
### Create a scene from a prompt
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import vgl
|
|
73
|
+
from vgl.dialects.thales import Generate
|
|
74
|
+
|
|
75
|
+
scene = vgl.create(Generate(prompt="a red fox in snow at dusk"))
|
|
76
|
+
print(scene.short_description)
|
|
77
|
+
print(scene.model_dump_json(indent=2, exclude_none=True))
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Edit from images
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from PIL import Image
|
|
84
|
+
from vgl.dialects.thales import EditImages
|
|
85
|
+
|
|
86
|
+
room = Image.open("room.jpg")
|
|
87
|
+
lamp = Image.open("lamp.jpg")
|
|
88
|
+
|
|
89
|
+
scene = vgl.modify(EditImages(prompt="make it night", images=[room]))
|
|
90
|
+
scene = vgl.modify(EditImages(prompt="put the lamp from <image_2> in <image_1>", images=[room, lamp]))
|
|
91
|
+
print(scene.edit_instruction)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Up to 4 images. The prompt refers to them as `<image_1>` to `<image_4>`, in list order.
|
|
95
|
+
|
|
96
|
+
### Edit a masked area
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from vgl.dialects.thales import EditImageWithMask
|
|
100
|
+
|
|
101
|
+
mask = Image.open("mask.png") # white is the area to change; same size as the image
|
|
102
|
+
scene = vgl.modify(EditImageWithMask(prompt="replace it with a cat", image=room, mask=mask))
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Edit with the image's VGL
|
|
106
|
+
|
|
107
|
+
If you have the VGL that an image was generated from, pass it as `input_image_vgl`. The edit then keeps everything the prompt doesn't change, rather than re-describing the image from scratch. vgl doesn't check that it matches the image.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
scene = vgl.create(Generate(prompt="a cosy living room"))
|
|
111
|
+
image = ... # generate the image from `scene` with FIBO
|
|
112
|
+
night = vgl.modify(EditImages(prompt="make it night", images=[image], input_image_vgl=scene))
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Runnable versions are in [`examples/`](https://github.com/Bria-AI/vgl/tree/dev/examples).
|
|
116
|
+
|
|
117
|
+
## Options
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
vgl.create(payload, llm="vertex_ai/gemini-3.5-flash-lite", seed=7, style_preset_prompt="Muted film colours, soft grain.")
|
|
121
|
+
vgl.modify(payload, llm=..., seed=...)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- `llm`: the litellm model id; see [Authenticate](#authenticate).
|
|
125
|
+
- `seed`: makes a call repeatable, on models that accept one.
|
|
126
|
+
- `style_preset_prompt`: style guidelines added to the system prompt. Applies to `create` only; `modify` ignores it.
|
|
127
|
+
vgl logs under the `vgl` logger hierarchy (`vgl.gateway`, `vgl.prompting`, …). Configure it the standard way — e.g. `logging.getLogger("vgl").setLevel(logging.INFO)` and attach your own handler; add a `logging.Filter` if you need to inject contextual fields.
|
|
128
|
+
|
|
129
|
+
A Gemini call that keeps failing (3 attempts) or hits a rate limit (429, not retried) moves to `gemini-3.1-flash-lite` on the same provider.
|
|
130
|
+
|
|
131
|
+
## Errors
|
|
132
|
+
|
|
133
|
+
Everything vgl raises inherits from `vgl.exceptions.VGLError`, except a bad payload, which raises `pydantic.ValidationError` before any LLM call. The classes below all live in `vgl.exceptions`.
|
|
134
|
+
|
|
135
|
+
| Error | Means |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `AuthenticationError` | the provider rejected your credentials, e.g. a missing or wrong API key |
|
|
138
|
+
| `RateLimitError` | the provider returned 429 (quota exhausted), on the Gemini fallback too |
|
|
139
|
+
| `LLMError` | any other provider failure, after retries and the fallback |
|
|
140
|
+
| `InvalidResponseError` | the model's reply isn't a valid VGL |
|
|
141
|
+
| `MaxTokensError` | the model ran out of output tokens mid-reply |
|
|
142
|
+
| `PromptNotFoundError` | a bundled prompt is missing; a packaging fault, please report it |
|
|
143
|
+
|
|
144
|
+
## Dialects
|
|
145
|
+
|
|
146
|
+
A dialect is a small variant of VGL, with its own model, payloads, and prompts. The payload you import decides the dialect. vgl ships the Thales dialect: no aesthetic scores, and every edit states its change in `edit_instruction`.
|
|
147
|
+
|
|
148
|
+
## More
|
|
149
|
+
|
|
150
|
+
- [Best practices](https://github.com/Bria-AI/vgl/blob/dev/docs/best_practices.md): how images are prepared, masks, and getting consistent results.
|
|
151
|
+
- [Contributing](https://github.com/Bria-AI/vgl/blob/dev/CONTRIBUTING.md)
|
bria_vgl-0.1.0/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# VGL — Visual Generation Language
|
|
2
|
+
|
|
3
|
+
VGL turns a text prompt, or images plus a prompt, into a structured JSON description of a scene: objects, background, lighting, aesthetics, camera, and text. The result is a typed Pydantic model that an image model like FIBO takes as its prompt.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install bria-vgl
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The default LLM is Gemini through Google AI Studio. For other providers, install the extra:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install 'bria-vgl[vertex]' # Gemini on Vertex AI
|
|
15
|
+
pip install 'bria-vgl[bedrock]' # Claude on AWS Bedrock
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Authenticate
|
|
19
|
+
|
|
20
|
+
| Provider | `llm=` | Set |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| Google AI Studio (default) | `gemini/gemini-3.5-flash-lite` | `GEMINI_API_KEY` ([get one](https://aistudio.google.com/apikey)) |
|
|
23
|
+
| Vertex AI | `vertex_ai/gemini-3.5-flash-lite` | `VERTEXAI_PROJECT`, `VERTEXAI_LOCATION`, `GOOGLE_APPLICATION_CREDENTIALS` (a service account JSON) |
|
|
24
|
+
| AWS Bedrock | e.g. `bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0` | the usual AWS credentials and `AWS_REGION_NAME` |
|
|
25
|
+
|
|
26
|
+
`llm` takes any [litellm model id](https://docs.litellm.ai/docs/providers), but the prompts are tuned for Gemini.
|
|
27
|
+
|
|
28
|
+
## Quickstart
|
|
29
|
+
|
|
30
|
+
### Create a scene from a prompt
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import vgl
|
|
34
|
+
from vgl.dialects.thales import Generate
|
|
35
|
+
|
|
36
|
+
scene = vgl.create(Generate(prompt="a red fox in snow at dusk"))
|
|
37
|
+
print(scene.short_description)
|
|
38
|
+
print(scene.model_dump_json(indent=2, exclude_none=True))
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Edit from images
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from PIL import Image
|
|
45
|
+
from vgl.dialects.thales import EditImages
|
|
46
|
+
|
|
47
|
+
room = Image.open("room.jpg")
|
|
48
|
+
lamp = Image.open("lamp.jpg")
|
|
49
|
+
|
|
50
|
+
scene = vgl.modify(EditImages(prompt="make it night", images=[room]))
|
|
51
|
+
scene = vgl.modify(EditImages(prompt="put the lamp from <image_2> in <image_1>", images=[room, lamp]))
|
|
52
|
+
print(scene.edit_instruction)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Up to 4 images. The prompt refers to them as `<image_1>` to `<image_4>`, in list order.
|
|
56
|
+
|
|
57
|
+
### Edit a masked area
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from vgl.dialects.thales import EditImageWithMask
|
|
61
|
+
|
|
62
|
+
mask = Image.open("mask.png") # white is the area to change; same size as the image
|
|
63
|
+
scene = vgl.modify(EditImageWithMask(prompt="replace it with a cat", image=room, mask=mask))
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Edit with the image's VGL
|
|
67
|
+
|
|
68
|
+
If you have the VGL that an image was generated from, pass it as `input_image_vgl`. The edit then keeps everything the prompt doesn't change, rather than re-describing the image from scratch. vgl doesn't check that it matches the image.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
scene = vgl.create(Generate(prompt="a cosy living room"))
|
|
72
|
+
image = ... # generate the image from `scene` with FIBO
|
|
73
|
+
night = vgl.modify(EditImages(prompt="make it night", images=[image], input_image_vgl=scene))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Runnable versions are in [`examples/`](https://github.com/Bria-AI/vgl/tree/dev/examples).
|
|
77
|
+
|
|
78
|
+
## Options
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
vgl.create(payload, llm="vertex_ai/gemini-3.5-flash-lite", seed=7, style_preset_prompt="Muted film colours, soft grain.")
|
|
82
|
+
vgl.modify(payload, llm=..., seed=...)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- `llm`: the litellm model id; see [Authenticate](#authenticate).
|
|
86
|
+
- `seed`: makes a call repeatable, on models that accept one.
|
|
87
|
+
- `style_preset_prompt`: style guidelines added to the system prompt. Applies to `create` only; `modify` ignores it.
|
|
88
|
+
vgl logs under the `vgl` logger hierarchy (`vgl.gateway`, `vgl.prompting`, …). Configure it the standard way — e.g. `logging.getLogger("vgl").setLevel(logging.INFO)` and attach your own handler; add a `logging.Filter` if you need to inject contextual fields.
|
|
89
|
+
|
|
90
|
+
A Gemini call that keeps failing (3 attempts) or hits a rate limit (429, not retried) moves to `gemini-3.1-flash-lite` on the same provider.
|
|
91
|
+
|
|
92
|
+
## Errors
|
|
93
|
+
|
|
94
|
+
Everything vgl raises inherits from `vgl.exceptions.VGLError`, except a bad payload, which raises `pydantic.ValidationError` before any LLM call. The classes below all live in `vgl.exceptions`.
|
|
95
|
+
|
|
96
|
+
| Error | Means |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `AuthenticationError` | the provider rejected your credentials, e.g. a missing or wrong API key |
|
|
99
|
+
| `RateLimitError` | the provider returned 429 (quota exhausted), on the Gemini fallback too |
|
|
100
|
+
| `LLMError` | any other provider failure, after retries and the fallback |
|
|
101
|
+
| `InvalidResponseError` | the model's reply isn't a valid VGL |
|
|
102
|
+
| `MaxTokensError` | the model ran out of output tokens mid-reply |
|
|
103
|
+
| `PromptNotFoundError` | a bundled prompt is missing; a packaging fault, please report it |
|
|
104
|
+
|
|
105
|
+
## Dialects
|
|
106
|
+
|
|
107
|
+
A dialect is a small variant of VGL, with its own model, payloads, and prompts. The payload you import decides the dialect. vgl ships the Thales dialect: no aesthetic scores, and every edit states its change in `edit_instruction`.
|
|
108
|
+
|
|
109
|
+
## More
|
|
110
|
+
|
|
111
|
+
- [Best practices](https://github.com/Bria-AI/vgl/blob/dev/docs/best_practices.md): how images are prepared, masks, and getting consistent results.
|
|
112
|
+
- [Contributing](https://github.com/Bria-AI/vgl/blob/dev/CONTRIBUTING.md)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "bria-vgl"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Turn a prompt, or images plus a prompt, into a structured JSON scene description (VGL) for image models like FIBO."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [{ name = "Bria AI" }]
|
|
9
|
+
keywords = ["vgl", "fibo", "bria", "image generation", "prompt", "structured output", "llm"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 3 - Alpha",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.10",
|
|
15
|
+
"Programming Language :: Python :: 3.11",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Programming Language :: Python :: 3.14",
|
|
19
|
+
"Topic :: Multimedia :: Graphics",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
requires-python = ">=3.10"
|
|
25
|
+
# vgl is a base package: every spec stays an open lower bound, floored at the oldest
|
|
26
|
+
# version whose API vgl actually uses. A hard pin here becomes a resolution conflict for
|
|
27
|
+
# every consumer, who then has to carry an override.
|
|
28
|
+
dependencies = [
|
|
29
|
+
# One function, boltons.iterutils.remap, stable for years.
|
|
30
|
+
"boltons>=20.0.0",
|
|
31
|
+
# The whole surface used is Image.Image/new/open/composite, Image.Resampling and
|
|
32
|
+
# .convert/.resize/.save. The newest of those, Image.Resampling, landed in 9.1.
|
|
33
|
+
"pillow>=9.1.0",
|
|
34
|
+
# The VGL models and payloads. v2-only API, so 2.0 is the honest floor.
|
|
35
|
+
"pydantic>=2.0",
|
|
36
|
+
# Floor is a version vgl is known to run on, not the newest release.
|
|
37
|
+
"litellm>=1.80.11",
|
|
38
|
+
# Imported for the base class of litellm's provider errors. Floor matches litellm's own.
|
|
39
|
+
"openai>=2.20.0",
|
|
40
|
+
# NOT used by vgl. litellm imports yaml at base import time
|
|
41
|
+
# (integrations/dotprompt/prompt_manager.py) but only declares pyyaml under its `cli`
|
|
42
|
+
# and `proxy` extras, so without this a clean install of vgl fails on `import vgl`
|
|
43
|
+
# with ModuleNotFoundError: yaml. Verified against litellm 1.90.0. Remove only once
|
|
44
|
+
# litellm declares it, or stops importing it unconditionally.
|
|
45
|
+
"pyyaml>=6.0.1",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://github.com/Bria-AI/vgl"
|
|
50
|
+
Documentation = "https://github.com/Bria-AI/vgl#readme"
|
|
51
|
+
Issues = "https://github.com/Bria-AI/vgl/issues"
|
|
52
|
+
Changelog = "https://github.com/Bria-AI/vgl/blob/dev/CHANGELOG.md"
|
|
53
|
+
|
|
54
|
+
[project.optional-dependencies]
|
|
55
|
+
# litellm reaches Vertex by doing `import google.auth` to read GOOGLE_APPLICATION_CREDENTIALS,
|
|
56
|
+
# but declares it only under its own extras — so nothing installs it and a clean vgl dies on the
|
|
57
|
+
# first Vertex call. Narrower than litellm's own suggestion of google-cloud-aiplatform, which is
|
|
58
|
+
# a far larger tree; google-auth is what litellm actually imports and is verified sufficient.
|
|
59
|
+
vertex = ["google-auth>=2.0"]
|
|
60
|
+
|
|
61
|
+
# litellm reaches Bedrock through boto3 but declares it under no extra of its own, so the failure
|
|
62
|
+
# is the same shape as the Vertex one: fine until the first call. vgl dropped boto3 in PR #45 as
|
|
63
|
+
# an unused direct import, which it still is — this is litellm's need, declared honestly.
|
|
64
|
+
bedrock = ["boto3>=1.34"]
|
|
65
|
+
|
|
66
|
+
# Every optional dependency, for a consumer that does not want to track which provider needs what.
|
|
67
|
+
all = ["bria-vgl[vertex]", "bria-vgl[bedrock]"]
|
|
68
|
+
|
|
69
|
+
# Local development only — PEP 735 groups are not published in the wheel, which is why the
|
|
70
|
+
# Vertex dependency above is an extra instead: a consumer has to be able to install it.
|
|
71
|
+
[dependency-groups]
|
|
72
|
+
# google-auth is the `vertex` extra's dependency; the Vertex validation tests import it.
|
|
73
|
+
test = ["pytest>=8.0.0", "google-auth>=2.0"]
|
|
74
|
+
|
|
75
|
+
lint = ["pyright>=1.1.408", "ruff>=0.15.12"]
|
|
76
|
+
|
|
77
|
+
# The smoke test loads a .env; python-dotenv otherwise arrives only transitively, via litellm.
|
|
78
|
+
examples = ["python-dotenv>=1.0"]
|
|
79
|
+
|
|
80
|
+
dev = [
|
|
81
|
+
{ include-group = "test" },
|
|
82
|
+
{ include-group = "lint" },
|
|
83
|
+
{ include-group = "examples" },
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
[build-system]
|
|
87
|
+
# 1.27 is the first to support the PEP 639 license fields.
|
|
88
|
+
requires = ["hatchling>=1.27"]
|
|
89
|
+
build-backend = "hatchling.build"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
[tool.hatch.metadata]
|
|
93
|
+
allow-direct-references = true
|
|
94
|
+
|
|
95
|
+
[tool.hatch.build.targets.wheel]
|
|
96
|
+
packages = ["src/vgl"]
|
|
97
|
+
|
|
98
|
+
[tool.hatch.build]
|
|
99
|
+
include = ["src/**/*"]
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
[tool.ruff.lint]
|
|
104
|
+
select = ["C4", "E", "F", "I", "PERF", "UP"]
|
|
105
|
+
ignore = ["PERF203"]
|
|
106
|
+
|
|
107
|
+
[tool.ruff]
|
|
108
|
+
line-length = 160
|
|
109
|
+
target-version = "py310"
|
|
110
|
+
|
|
111
|
+
[tool.pytest.ini_options]
|
|
112
|
+
log_cli = true
|
|
113
|
+
python_files = ["*_tests.py"]
|
|
114
|
+
testpaths = ["tests"]
|
|
115
|
+
markers = [
|
|
116
|
+
"unit: isolated, no I/O beyond tmp_path and the bundled package data",
|
|
117
|
+
"integration: several real components together, still no network",
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
[tool.pyright]
|
|
121
|
+
enableExperimentalFeatures = true
|
|
122
|
+
exclude = ["**/.venv", "**/node_modules", "**/__pycache__"]
|
|
123
|
+
|
|
124
|
+
[tool.commitizen]
|
|
125
|
+
name = "cz_conventional_commits"
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from litellm.exceptions import AuthenticationError as LiteLLMAuthenticationError
|
|
4
|
+
from litellm.exceptions import RateLimitError as LiteLLMRateLimitError
|
|
5
|
+
from openai import OpenAIError
|
|
6
|
+
|
|
7
|
+
from vgl import gateway
|
|
8
|
+
from vgl.exceptions import AuthenticationError, LLMError, RateLimitError
|
|
9
|
+
from vgl.payload import Payload, T
|
|
10
|
+
from vgl.prompting import render_prompts
|
|
11
|
+
from vgl.utils.vertex import validate_vertex_env
|
|
12
|
+
|
|
13
|
+
DEFAULT_LLM = "gemini/gemini-3.5-flash-lite"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def create(payload: Payload[T], *, llm: str = DEFAULT_LLM, style_preset_prompt: str | None = None, seed: int | None = None) -> T:
|
|
17
|
+
"""A new VGL. ``style_preset_prompt`` is composed into the system prompt."""
|
|
18
|
+
if not payload.creates:
|
|
19
|
+
raise TypeError(f"{type(payload).__name__} edits a VGL; pass it to vgl.modify()")
|
|
20
|
+
return _run(payload, llm=llm, seed=seed, style_preset=style_preset_prompt)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def modify(payload: Payload[T], *, llm: str = DEFAULT_LLM, style_preset_prompt: str | None = None, seed: int | None = None) -> T:
|
|
24
|
+
"""An edited VGL. ``style_preset_prompt`` is accepted and ignored: presets apply to create only."""
|
|
25
|
+
if payload.creates:
|
|
26
|
+
raise TypeError(f"{type(payload).__name__} creates a VGL; pass it to vgl.create()")
|
|
27
|
+
return _run(payload, llm=llm, seed=seed, style_preset=None)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _check_gemini_key(llm: str) -> None:
|
|
31
|
+
"""litellm reports a missing key as a connection error, which the gateway would retry."""
|
|
32
|
+
if llm.startswith("gemini/") and not (os.environ.get("GEMINI_API_KEY") or os.environ.get("GOOGLE_API_KEY")):
|
|
33
|
+
raise AuthenticationError(f"{llm} needs GEMINI_API_KEY or GOOGLE_API_KEY set")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _run(payload: Payload[T], *, llm: str, seed: int | None, style_preset: str | None) -> T:
|
|
37
|
+
validate_vertex_env(llm)
|
|
38
|
+
_check_gemini_key(llm)
|
|
39
|
+
request = payload.to_request()
|
|
40
|
+
system_prompt, user_prompt = render_prompts(request.prompts, request.context, style_preset)
|
|
41
|
+
try:
|
|
42
|
+
text = gateway.call(
|
|
43
|
+
model_name=llm,
|
|
44
|
+
system_prompt=system_prompt,
|
|
45
|
+
user_prompt=user_prompt,
|
|
46
|
+
images=list(request.images),
|
|
47
|
+
seed=seed,
|
|
48
|
+
response_schema=request.response_schema,
|
|
49
|
+
temperature=request.temperature,
|
|
50
|
+
)
|
|
51
|
+
except LiteLLMAuthenticationError as error:
|
|
52
|
+
raise AuthenticationError(str(error)) from error
|
|
53
|
+
except LiteLLMRateLimitError as error:
|
|
54
|
+
raise RateLimitError(str(error)) from error
|
|
55
|
+
# Every litellm provider error subclasses openai's.
|
|
56
|
+
except OpenAIError as error:
|
|
57
|
+
raise LLMError(str(error)) from error
|
|
58
|
+
return payload.parse(text)
|