Commit Graph

8218 Commits

Author SHA1 Message Date
psychedelicious
9195c8c957 feat: dedicated route to get intermediates count
This fixes a weird issue where the list images method needed to handle `None` for its `limit` and `offset` arguments, in order to get a count of all intermediates.
2023-10-19 16:58:51 +11:00
Millun Atluri
677918df61
Docs Update (python version & T2I (#4867)
* Updated Control Adapter Docs

* fixed typo

* Update docs for 3.10

* Update diffusers language

Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>

* Diffusers format

Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>

* Current T2I Adapter usage

Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>

* Update test-invoke-pip.yml

---------

Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>
2023-10-18 23:38:31 -04:00
psychedelicious
96e80c71fb chore: lint 2023-10-19 08:52:02 +11:00
psychedelicious
da403ba04c fix(api): flesh out types for api_app.py 2023-10-19 08:52:02 +11:00
psychedelicious
e4c45012f4 feat(api): add gzip middleware
On our local installs this will be a very minor change. For those running on remote servers, load times should be slightly improved.

It's a small change but I think correct.
2023-10-19 08:52:02 +11:00
psychedelicious
ef14ba1713 fix(api): fix uvicorn config loop arg
We were providing the loop itself, not the kind of loop. This didn't appear to cause any issues whatsoever, but now it's correct.
2023-10-19 08:52:02 +11:00
psychedelicious
9e06371178 feat(api): serve app via route & add cache-control: no-store
This should prevent `index.html` from *ever* being cached, so UIs will never be out of date.

Minor organisation to accomodate this.

Deleting old unused files from the early days
2023-10-19 08:52:02 +11:00
psychedelicious
a459786d73 fix(nodes): enable number to string coercion 2023-10-19 08:43:08 +11:00
d8ahazard
fdf02c33d0 Catch generic model errors
Prevent the app from dying on invalid models.
2023-10-19 07:28:33 +11:00
psychedelicious
0a01d86ab1 fix(ui): fix multiple control adapters on canvas
We were making an edges for each adapter where we should isntead have one from the adapter's collect node into the denoising node
2023-10-19 07:15:27 +11:00
psychedelicious
5e6df975fd fix(nodes): fix math node validation
Update field_validator api for pydantic v2
2023-10-19 06:50:00 +11:00
Ryan Dick
967a2dad54
Multi-Image IP-Adapter (#4882)
## What type of PR is this? (check all applicable)

- [ ] Refactor
- [x] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Community Node Submission

## Description

This PR adds the ability to pass multiple images to a single IP-Adapter
(note the difference from using _multiple IP-Adapters at once_, which is
already supported.). The image embeddings are combined in the IP-Adapter
attention layers. This is the same strategy for combining multiple
images as used in Insta-LoRA workflows
(https://civitai.com/articles/2345).

This PR only adds multi-image support in the backend and the node
editor. The Linear UI still needs to be updated.

## QA Instructions, Screenshots, Recordings

I have manually tested the following via the workflow editor:
- Multiple images with a single IP-Adapter
- Multiple images per IP-Adapter, and multiple IP-Adapters
- Both standard and sequential conditioning
- IP-Adapters still work in the Linear UI.

Please hammer at this feature some more with manual testing.

## Added/updated tests?

- [x] Yes
- [ ] No

I updated the existing IP-Adapter smoke test, but it provides pretty
limited coverage of this feature. This feature would probably be best
tested by an end-to-end workflow test, which is not currently supported.
(I'm hoping to put some effort into workflow-level testing soon.)
2023-10-18 10:17:34 -04:00
Ryan Dick
a078efc0f2 Merge branch 'main' into ryan/multi-image-ip 2023-10-18 08:59:12 -04:00
psychedelicious
024aa5eb90 fix(ui): fix field sorting
closes #4934
2023-10-18 15:35:26 +11:00
psychedelicious
67a343b3e4 Update pyproject.toml 2023-10-18 11:28:26 +11:00
Lincoln Stein
d27392cc2d remove all references to CLI 2023-10-18 11:28:26 +11:00
blessedcoolant
9fa8e38163
fix(ui): use pidi processor for sketch (#4931)
## What type of PR is this? (check all applicable)

- [ ] Refactor
- [ ] Feature
- [x] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Community Node Submission


## Have you discussed this change with the InvokeAI team?
- [x] Yes
- [ ] No, because:

## Description

fix(ui): use pidi processor for sketch control adapters
2023-10-18 04:04:42 +05:30
blessedcoolant
4b197cb6d4
Merge branch 'main' into fix/ui/sketch-pidi-processor 2023-10-18 04:02:30 +05:30
psychedelicious
252c9a5f5a fix(backend): fix nsfw/watermarker util types 2023-10-18 09:08:13 +11:00
psychedelicious
975ba6b74f fix(ui): use pidi processor for sketch 2023-10-18 08:43:56 +11:00
psychedelicious
284a257c25
feat: remove enqueue_graph routes/methods (#4922)
This is totally extraneous - it's almost identical to `enqueue_batch`.
2023-10-17 18:00:40 +00:00
psychedelicious
58a0709c1e Revert "Fixing some var and arg names."
This reverts commit f11ba81a8d.
2023-10-17 11:59:11 -04:00
psychedelicious
c04fb451ee Revert "Changes to _apply_standard_conditioning_sequentially() and _apply_cross_attention_controlled_conditioning() to reflect changes to T2I-Adapter implementation to allow usage of T2I-Adapter and ControlNet at the same time."
This reverts commit 378689a519.
2023-10-17 11:59:11 -04:00
psychedelicious
6e697b7b6f Revert "Cleaning up (removing diagnostic prints)"
This reverts commit 06f8a3276d.
2023-10-17 11:59:11 -04:00
psychedelicious
38e7eb8878 Revert "chore: lint"
This reverts commit fff29d663d.
2023-10-17 11:59:11 -04:00
psychedelicious
bdf4c4944c Revert "feat(ui): remove special handling for t2i vs controlnet"
This reverts commit b146993553.
2023-10-17 11:59:11 -04:00
psychedelicious
b146993553 feat(ui): remove special handling for t2i vs controlnet 2023-10-17 19:42:06 +11:00
psychedelicious
fff29d663d chore: lint 2023-10-17 19:42:06 +11:00
user1
06f8a3276d Cleaning up (removing diagnostic prints) 2023-10-17 19:42:06 +11:00
user1
378689a519 Changes to _apply_standard_conditioning_sequentially() and _apply_cross_attention_controlled_conditioning() to reflect changes to T2I-Adapter implementation to allow usage of T2I-Adapter and ControlNet at the same time.
Also, the PREVIOUS commit (@8d3885d, which was already pushed to github repo) was wrongly commented, but too late to fix without a force push or other mucking that I'm reluctant to do. That commit is actually the one that has all the changes to diffusers_pipeline.py to use additional arg down_intrablock_additional_residuals (introduced in diffusers PR https://github.com/huggingface/diffusers/pull/5362) to detangle T2I-Adapter from ControlNet inputs to main UNet.
2023-10-17 19:42:06 +11:00
user1
f11ba81a8d Fixing some var and arg names. 2023-10-17 19:42:06 +11:00
Lincoln Stein
9542883bb5 update requirements to python 3.10-11 2023-10-17 19:30:31 +11:00
Surisen
c69715636d translationBot(ui): update translation (Chinese (Simplified))
Currently translated at 100.0% (1217 of 1217 strings)

Co-authored-by: Surisen <zhonghx0804@outlook.com>
Translate-URL: https://hosted.weblate.org/projects/invokeai/web-ui/zh_Hans/
Translation: InvokeAI/Web UI
2023-10-17 16:42:37 +11:00
psychedelicious
a094f4ca2b fix: pin python-socketio~=5.10.0 2023-10-17 14:59:25 +11:00
psychedelicious
9d9592230a chore: lint 2023-10-17 14:59:25 +11:00
psychedelicious
685cda89ff feat(api): restore get_session route 2023-10-17 14:59:25 +11:00
psychedelicious
2c39557dc9 fix(nodes): fix metadata validation error 2023-10-17 14:59:25 +11:00
psychedelicious
c238a7f18b feat(api): chore: pydantic & fastapi upgrade
Upgrade pydantic and fastapi to latest.

- pydantic~=2.4.2
- fastapi~=103.2
- fastapi-events~=0.9.1

**Big Changes**

There are a number of logic changes needed to support pydantic v2. Most changes are very simple, like using the new methods to serialized and deserialize models, but there are a few more complex changes.

**Invocations**

The biggest change relates to invocation creation, instantiation and validation.

Because pydantic v2 moves all validation logic into the rust pydantic-core, we may no longer directly stick our fingers into the validation pie.

Previously, we (ab)used models and fields to allow invocation fields to be optional at instantiation, but required when `invoke()` is called. We directly manipulated the fields and invocation models when calling `invoke()`.

With pydantic v2, this is much more involved. Changes to the python wrapper do not propagate down to the rust validation logic - you have to rebuild the model. This causes problem with concurrent access to the invocation classes and is not a free operation.

This logic has been totally refactored and we do not need to change the model any more. The details are in `baseinvocation.py`, in the `InputField` function and `BaseInvocation.invoke_internal()` method.

In the end, this implementation is cleaner.

**Invocation Fields**

In pydantic v2, you can no longer directly add or remove fields from a model.

Previously, we did this to add the `type` field to invocations.

**Invocation Decorators**

With pydantic v2, we instead use the imperative `create_model()` API to create a new model with the additional field. This is done in `baseinvocation.py` in the `invocation()` wrapper.

A similar technique is used for `invocation_output()`.

**Minor Changes**

There are a number of minor changes around the pydantic v2 models API.

**Protected `model_` Namespace**

All models' pydantic-provided methods and attributes are prefixed with `model_` and this is considered a protected namespace. This causes some conflict, because "model" means something to us, and we have a ton of pydantic models with attributes starting with "model_".

Forunately, there are no direct conflicts. However, in any pydantic model where we define an attribute or method that starts with "model_", we must tell set the protected namespaces to an empty tuple.

```py
class IPAdapterModelField(BaseModel):
    model_name: str = Field(description="Name of the IP-Adapter model")
    base_model: BaseModelType = Field(description="Base model")

    model_config = ConfigDict(protected_namespaces=())
```

**Model Serialization**

Pydantic models no longer have `Model.dict()` or `Model.json()`.

Instead, we use `Model.model_dump()` or `Model.model_dump_json()`.

**Model Deserialization**

Pydantic models no longer have `Model.parse_obj()` or `Model.parse_raw()`, and there are no `parse_raw_as()` or `parse_obj_as()` functions.

Instead, you need to create a `TypeAdapter` object to parse python objects or JSON into a model.

```py
adapter_graph = TypeAdapter(Graph)
deserialized_graph_from_json = adapter_graph.validate_json(graph_json)
deserialized_graph_from_dict = adapter_graph.validate_python(graph_dict)
```

**Field Customisation**

Pydantic `Field`s no longer accept arbitrary args.

Now, you must put all additional arbitrary args in a `json_schema_extra` arg on the field.

**Schema Customisation**

FastAPI and pydantic schema generation now follows the OpenAPI version 3.1 spec.

This necessitates two changes:
- Our schema customization logic has been revised
- Schema parsing to build node templates has been revised

The specific aren't important, but this does present additional surface area for bugs.

**Performance Improvements**

Pydantic v2 is a full rewrite with a rust backend. This offers a substantial performance improvement (pydantic claims 5x to 50x depending on the task). We'll notice this the most during serialization and deserialization of sessions/graphs, which happens very very often - a couple times per node.

I haven't done any benchmarks, but anecdotally, graph execution is much faster. Also, very larges graphs - like with massive iterators - are much, much faster.
2023-10-17 14:59:25 +11:00
psychedelicious
19c5435332 fix(ui): copy image via img onload to blob
There's a bug in chrome that screws with headers on fetch requests and 307 responses. This causes images to fail to copy in the commercial environment.

This change attempts to get around this by copying images in a different way (similar to how the canvas works). When the user requests a copy we:
- create an `<img />` element
- set `crossOrigin` if needed
- add an onload handler:
  - create a canvas element
  - draw image onto it
  - export canvas to blob

This is wrapped in a promise which resolves to the blob, which can then be copied to clipboard.

---

A customized version of Konva's `useImage` hook is also included, which returns the image blob in addition to the `<img />` element. Unfortunately, this hook is not suitable for use across the app, because it does all the image fetching up front, regardless of whether we actually want to copy the image.

In other words, we'd have to fetch the whole image file even if the user is just skipping through image metadata, in order to have the blob to copy. The callback approach means we only fetch the image when the user clicks copy. The hook is thus currently unused.
2023-10-17 06:43:19 +11:00
Ryan Dick
3079c75a60 (minor) Make it more clear that shape annotations are just comments and not commented lines of code. 2023-10-16 08:35:32 -04:00
psychedelicious
53b6f0dc73
Merge branch 'main' into ryan/multi-image-ip 2023-10-16 17:16:10 +11:00
blessedcoolant
70a1202deb
fix(api): fix socketio breaking change (#4901)
## What type of PR is this? (check all applicable)

- [ ] Refactor
- [ ] Feature
- [x] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Community Node Submission


## Have you discussed this change with the InvokeAI team?
- [x] Yes
- [ ] No, because:

## Description

Fix for breaking change in `python-socketio` 5.10.0 in which
`enter_room` and `leave_room` were made coroutines.

## Related Tickets & Documents

<!--
For pull requests that relate or close an issue, please include them
below. 

For example having the text: "closes #1234" would connect the current
pull
request to issue 1234.  And when we merge the pull request, Github will
automatically close the issue.
-->


- Closes #4899
2023-10-16 07:29:31 +05:30
psychedelicious
9a1aea9caf fix(api): fix socketio breaking change
Fix for breaking change in `python-socketio` 5.10.0 in which `enter_room` and `leave_room` were made coroutines.
2023-10-16 12:18:46 +11:00
psychedelicious
388d36b839 fix(db): use RLock instead of Lock
Fixes issues where a db-accessing service wants to call db-accessing methods with locks.
2023-10-16 11:45:24 +11:00
Surisen
bedb35af8c translationBot(ui): update translation (Chinese (Simplified))
Currently translated at 100.0% (1217 of 1217 strings)

Co-authored-by: Surisen <zhonghx0804@outlook.com>
Translate-URL: https://hosted.weblate.org/projects/invokeai/web-ui/zh_Hans/
Translation: InvokeAI/Web UI
2023-10-16 07:57:41 +11:00
Riccardo Giovanetti
dc232438fb translationBot(ui): update translation (Italian)
Currently translated at 97.5% (1187 of 1217 strings)

Co-authored-by: Riccardo Giovanetti <riccardo.giovanetti@gmail.com>
Translate-URL: https://hosted.weblate.org/projects/invokeai/web-ui/it/
Translation: InvokeAI/Web UI
2023-10-16 07:57:41 +11:00
blessedcoolant
d7edf5aaad
fix(ui): fix control adapter translation string (#4888)
## What type of PR is this? (check all applicable)

- [ ] Refactor
- [ ] Feature
- [x] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Community Node Submission

## Description

fix(ui): fix control adapter translation string

Missed this during a previous change

## Related Tickets & Documents

<!--
For pull requests that relate or close an issue, please include them
below. 

For example having the text: "closes #1234" would connect the current
pull
request to issue 1234.  And when we merge the pull request, Github will
automatically close the issue.
-->

Reported by @Harvester62 :

https://discord.com/channels/1020123559063990373/1054129386447716433/1162018775437148160
2023-10-15 18:19:41 +05:30
blessedcoolant
3ad1226d1e
Merge branch 'main' into fix/ui/control-adapter-translation-string 2023-10-15 18:16:48 +05:30
blessedcoolant
86ca9f122d
Strip whitespace from model URLs (#4863)
## What type of PR is this? (check all applicable)

- [ ] Refactor
- [ ] Feature
- [X] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Community Node Submission


## Have you discussed this change with the InvokeAI team?
- [X] Yes
- [ ] No, because:

      
## Have you updated all relevant documentation?
- [X] Yes
- [ ] No


## Description

This PR strips leading and trailing whitespace from URLs that are
entered into either the Web Model Manager import field, or using the
TUI.

## Related Tickets & Documents

Closes #4536


## QA Instructions, Screenshots, Recordings

Try to import a URL with leading or trailing whitespace. Should not work
in current main. This PR should fix it.
2023-10-15 17:53:20 +05:30
blessedcoolant
2c6772f92f
Merge branch 'main' into bugfix/trim-whitespace-from-urls 2023-10-15 17:41:41 +05:30