Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: integrates spandrel for upscaling #464

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pip
cache-dependency-path: requirements-dev.txt
- name: Install dependencies
run: |
python -m pip install uv
Expand Down Expand Up @@ -108,6 +106,8 @@ jobs:
build-wheel:
name: Build Wheel
runs-on: ubuntu-latest
outputs:
wheel_name: ${{ steps.set_wheel_name.outputs.wheel_name }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4.5.0
Expand All @@ -117,8 +117,9 @@ jobs:
run: python -m pip install wheel
- name: Build package
run: python setup.py bdist_wheel
- name: Rename wheel
run: mv dist/*.whl dist/imaginAIry-0.0.1b0-py3-none-any.whl
- name: Set wheel filename
id: set_wheel_name
run: echo "wheel_name=$(ls dist/*.whl)" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v3
with:
name: wheels
Expand All @@ -142,11 +143,14 @@ jobs:
name: wheels
path: dist
- name: Install built wheel
env:
WHEEL_FILENAME: ${{ needs.build-wheel.outputs.wheel_name }}
run: |
python -m pip install dist/imaginAIry-0.0.1b0-py3-none-any.whl
python -m pip install uv
uv pip install --system ${{ needs.build-wheel.outputs.wheel_name }}
- name: Generate an image
run: |
imagine fruit --steps 10 --size 512 --seed 1
imagine fruit --steps 3 --size 512 --seed 1
- uses: actions/upload-artifact@v3
with:
name: images
Expand Down Expand Up @@ -174,14 +178,17 @@ jobs:
path: dist
- name: Install built wheel
shell: bash -l {0}
env:
WHEEL_FILENAME: ${{ steps.set-wheel-name.outputs.WHEEL_FILENAME }}
run: |
conda activate test-env
python -m pip install dist/imaginAIry-0.0.1b0-py3-none-any.whl
python -m pip install uv
uv pip install ${{ needs.build-wheel.outputs.wheel_name }}
- name: Generate an image
shell: bash -l {0}
run: |
conda activate test-env
imagine fruit --steps 10 --size 512 --seed 1
imagine fruit --steps 3 --size 512 --seed 1
- uses: actions/upload-artifact@v3
with:
name: images
Expand Down
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Options:

### Whats New
[See full Changelog here](./docs/changelog.md)
**14.2.1**
- feature: integrates spandrel for upscaling.

**14.2.0**
- 🎉 feature: add image prompt support via `--image-prompt` and `--image-prompt-strength`
Expand Down Expand Up @@ -352,14 +354,28 @@ When writing strength modifiers keep in mind that pixel values are between 0 and
<img src="https://github.com/brycedrennan/imaginAIry/raw/master/assets/000178_1_PLMS40_PS7.5_a_couple_smiling_fixed.png" height="256">


### Upscaling [by RealESRGAN](https://github.com/xinntao/Real-ESRGAN)
```bash
>> imagine "colorful smoke" --steps 40 --upscale
# upscale an existing image
>> aimg upscale my-image.jpg
```
<details>
<summary>Python Example</summary>
## Image Upscaling
Upscale images easily.

=== "CLI"
```bash
aimg upscale assets/000206_856637805_PLMS40_PS7.5_colorful_smoke.jpg --upscale-model real-hat
```

=== "Python"
```py
from imaginairy.api.upscale import upscale

img = upscale(img="assets/000206_856637805_PLMS40_PS7.5_colorful_smoke.jpg")
img.save("colorful_smoke.upscaled.jpg")

```
<img src="docs/assets/000206_856637805_PLMS40_PS7.5_colorful_smoke.jpg" width="25%" height="auto"> ➡️
<img src="docs/assets/000206_856637805_PLMS40_PS7.5_colorful_smoke_upscaled.jpg" width="50%" height="auto">

Upscaling uses [Spandrel](https://github.com/chaiNNer-org/spandrel) to make it easy to use different upscaling models.
You can view different integrated models by running `aimg upscale --list-models`, and then use it with `--upscale-model <model-name>`.
Also accepts url's if you want to upscale an image with a different model. Control the new file format/location with --format.

```python
from imaginairy.enhancers.upscale_realesrgan import upscale_image
Expand All @@ -368,9 +384,7 @@ img = Image.open("my-image.jpg")
big_img = upscale_image(i)
```

</details>
<img src="https://github.com/brycedrennan/imaginAIry/raw/master/assets/000206_856637805_PLMS40_PS7.5_colorful_smoke.jpg" height="128"> ➡️
<img src="https://github.com/brycedrennan/imaginAIry/raw/master/assets/000206_856637805_PLMS40_PS7.5_colorful_smoke_upscaled.jpg" height="256">


### Tiled Images
```bash
Expand Down
Loading
Loading