loracraft 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.
Files changed (77) hide show
  1. loracraft-0.1.0/.github/workflows/release.yml +31 -0
  2. loracraft-0.1.0/.gitignore +9 -0
  3. loracraft-0.1.0/LICENSE +201 -0
  4. loracraft-0.1.0/PKG-INFO +160 -0
  5. loracraft-0.1.0/README.md +125 -0
  6. loracraft-0.1.0/hatch_build.py +13 -0
  7. loracraft-0.1.0/pyproject.toml +113 -0
  8. loracraft-0.1.0/src/loracraft/__init__.py +1 -0
  9. loracraft-0.1.0/src/loracraft/__main__.py +6 -0
  10. loracraft-0.1.0/src/loracraft/imaging.py +15 -0
  11. loracraft-0.1.0/src/loracraft/server/__init__.py +0 -0
  12. loracraft-0.1.0/src/loracraft/server/app.py +110 -0
  13. loracraft-0.1.0/src/loracraft/server/datasets.py +312 -0
  14. loracraft-0.1.0/src/loracraft/server/db.py +136 -0
  15. loracraft-0.1.0/src/loracraft/server/runs.py +425 -0
  16. loracraft-0.1.0/src/loracraft/server/system.py +123 -0
  17. loracraft-0.1.0/src/loracraft/server/tagging.py +367 -0
  18. loracraft-0.1.0/src/loracraft/server/tagging_prompt.py +114 -0
  19. loracraft-0.1.0/src/loracraft/trainer/__init__.py +7 -0
  20. loracraft-0.1.0/src/loracraft/trainer/__main__.py +16 -0
  21. loracraft-0.1.0/src/loracraft/trainer/bucketing.py +46 -0
  22. loracraft-0.1.0/src/loracraft/trainer/config.py +85 -0
  23. loracraft-0.1.0/src/loracraft/trainer/data.py +113 -0
  24. loracraft-0.1.0/src/loracraft/trainer/device.py +29 -0
  25. loracraft-0.1.0/src/loracraft/trainer/events.py +21 -0
  26. loracraft-0.1.0/src/loracraft/trainer/loop.py +384 -0
  27. loracraft-0.1.0/src/loracraft/trainer/sdxl.py +135 -0
  28. loracraft-0.1.0/src/loracraft/vendor/__init__.py +0 -0
  29. loracraft-0.1.0/src/loracraft/vendor/kohya/LICENSE +201 -0
  30. loracraft-0.1.0/src/loracraft/vendor/kohya/README.md +17 -0
  31. loracraft-0.1.0/src/loracraft/vendor/kohya/__init__.py +1 -0
  32. loracraft-0.1.0/src/loracraft/vendor/kohya/hashing.py +48 -0
  33. loracraft-0.1.0/src/loracraft/vendor/kohya/lora.py +306 -0
  34. loracraft-0.1.0/src/loracraft/vendor/kohya/sdxl_keys.py +121 -0
  35. loracraft-0.1.0/src/loracraft/vendor/kohya/train_functions.py +119 -0
  36. loracraft-0.1.0/src/loracraft/web_dist/assets/bricolage-grotesque-latin-ext-wght-normal-CcLUaPy7.woff2 +0 -0
  37. loracraft-0.1.0/src/loracraft/web_dist/assets/bricolage-grotesque-latin-wght-normal-DLoelf7F.woff2 +0 -0
  38. loracraft-0.1.0/src/loracraft/web_dist/assets/bricolage-grotesque-vietnamese-wght-normal-BUzh504Q.woff2 +0 -0
  39. loracraft-0.1.0/src/loracraft/web_dist/assets/index-Cc11kEew.css +1 -0
  40. loracraft-0.1.0/src/loracraft/web_dist/assets/index-Chx5XfHC.js +6 -0
  41. loracraft-0.1.0/src/loracraft/web_dist/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
  42. loracraft-0.1.0/src/loracraft/web_dist/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
  43. loracraft-0.1.0/src/loracraft/web_dist/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
  44. loracraft-0.1.0/src/loracraft/web_dist/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
  45. loracraft-0.1.0/src/loracraft/web_dist/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
  46. loracraft-0.1.0/src/loracraft/web_dist/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
  47. loracraft-0.1.0/src/loracraft/web_dist/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
  48. loracraft-0.1.0/src/loracraft/web_dist/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  49. loracraft-0.1.0/src/loracraft/web_dist/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  50. loracraft-0.1.0/src/loracraft/web_dist/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  51. loracraft-0.1.0/src/loracraft/web_dist/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  52. loracraft-0.1.0/src/loracraft/web_dist/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  53. loracraft-0.1.0/src/loracraft/web_dist/index.html +13 -0
  54. loracraft-0.1.0/tests/test_datasets.py +111 -0
  55. loracraft-0.1.0/tests/test_runs.py +123 -0
  56. loracraft-0.1.0/tests/test_tagging.py +58 -0
  57. loracraft-0.1.0/tests/test_trainer_units.py +61 -0
  58. loracraft-0.1.0/uv.lock +1058 -0
  59. loracraft-0.1.0/web/index.html +12 -0
  60. loracraft-0.1.0/web/package-lock.json +1636 -0
  61. loracraft-0.1.0/web/package.json +26 -0
  62. loracraft-0.1.0/web/src/App.svelte +523 -0
  63. loracraft-0.1.0/web/src/app.css +239 -0
  64. loracraft-0.1.0/web/src/lib/DatasetView.svelte +734 -0
  65. loracraft-0.1.0/web/src/lib/NewProjectDialog.svelte +126 -0
  66. loracraft-0.1.0/web/src/lib/ResultsView.svelte +489 -0
  67. loracraft-0.1.0/web/src/lib/SettingsDialog.svelte +106 -0
  68. loracraft-0.1.0/web/src/lib/TagChips.svelte +123 -0
  69. loracraft-0.1.0/web/src/lib/TaggingPanel.svelte +543 -0
  70. loracraft-0.1.0/web/src/lib/TrainMonitor.svelte +390 -0
  71. loracraft-0.1.0/web/src/lib/TrainSetup.svelte +604 -0
  72. loracraft-0.1.0/web/src/lib/TrainView.svelte +86 -0
  73. loracraft-0.1.0/web/src/lib/api.ts +268 -0
  74. loracraft-0.1.0/web/src/main.ts +5 -0
  75. loracraft-0.1.0/web/svelte.config.js +3 -0
  76. loracraft-0.1.0/web/tsconfig.json +12 -0
  77. loracraft-0.1.0/web/vite.config.ts +13 -0
@@ -0,0 +1,31 @@
1
+ name: Release
2
+
3
+ # Publishing a GitHub release builds the distributions and uploads them to PyPI through
4
+ # trusted publishing: no token is stored here. PyPI must list this repository, this workflow
5
+ # file and the `pypi` environment as a trusted publisher of the project.
6
+ on:
7
+ release:
8
+ types: [published]
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ environment: pypi
14
+ permissions:
15
+ id-token: write
16
+ contents: read
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: actions/setup-node@v4
20
+ with:
21
+ node-version: 22
22
+ cache: npm
23
+ cache-dependency-path: web/package-lock.json
24
+ - name: Build the web UI
25
+ working-directory: web
26
+ run: npm ci && npm run build
27
+ - uses: astral-sh/setup-uv@v6
28
+ - name: Check that the tag matches the package version
29
+ run: test "v$(uv version --short)" = "$GITHUB_REF_NAME"
30
+ - run: uv build
31
+ - run: uv publish
@@ -0,0 +1,9 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ node_modules/
5
+ src/loracraft/web_dist/
6
+ dist/
7
+ workspace/
8
+ .ruff_cache/
9
+ .pytest_cache/
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2022] [kohya-ss]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,160 @@
1
+ Metadata-Version: 2.5
2
+ Name: loracraft
3
+ Version: 0.1.0
4
+ Summary: LoRA training workbench with dataset, run and result management
5
+ Project-URL: Homepage, https://github.com/aisk/loracraft
6
+ Project-URL: Issues, https://github.com/aisk/loracraft/issues
7
+ Author: An Long
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ License-File: src/loracraft/vendor/kohya/LICENSE
11
+ Keywords: dataset,lora,sdxl,stable-diffusion,training
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: GPU
14
+ Classifier: Environment :: Web Environment
15
+ Classifier: Intended Audience :: End Users/Desktop
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: <3.13,>=3.12
19
+ Requires-Dist: accelerate>=1.10
20
+ Requires-Dist: diffusers>=0.35
21
+ Requires-Dist: fastapi>=0.118
22
+ Requires-Dist: httpx>=0.28
23
+ Requires-Dist: numpy>=2
24
+ Requires-Dist: pillow>=11
25
+ Requires-Dist: prodigyopt>=1.1.2
26
+ Requires-Dist: pydantic>=2.11
27
+ Requires-Dist: python-multipart>=0.0.33
28
+ Requires-Dist: safetensors>=0.6
29
+ Requires-Dist: torch>=2.4
30
+ Requires-Dist: transformers>=5.0
31
+ Requires-Dist: uvicorn[standard]>=0.37
32
+ Provides-Extra: app
33
+ Requires-Dist: pywebview>=5; extra == 'app'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # LoraCraft
37
+
38
+ A LoRA training workbench: manage datasets, captions, training runs and results in one place.
39
+ SDXL first.
40
+
41
+ ## What it does
42
+
43
+ - **Dataset**: import images with their captions, browse and filter by tag, edit tags one image at a
44
+ time or in bulk, spot missing captions and undersized images.
45
+ - **Auto-captioning**: a vision LLM (any OpenAI-compatible endpoint, local or hosted) writes captions
46
+ according to what the LoRA is for: a character, a style or a concept. Results are suggestions you
47
+ accept or discard; with a tag dictionary installed, invented tags are flagged or corrected.
48
+ - **Training**: a self-contained SDXL LoRA trainer with plain-language setup, a queue, live progress
49
+ and preview images after every round.
50
+ - **Results**: preview images of every round side by side, pick the best round, export it.
51
+
52
+ ## Layout
53
+
54
+ ```
55
+ src/loracraft/
56
+ server/ FastAPI backend: projects, dataset, auto-captioning, run queue
57
+ trainer/ SDXL LoRA trainer, runs as its own process
58
+ vendor/kohya/ code adapted from kohya-ss/sd-scripts (Apache-2.0)
59
+ web/ Svelte frontend
60
+ tests/
61
+ ```
62
+
63
+ ## Install
64
+
65
+ Requires Python 3.12. Training needs a GPU that PyTorch drives through CUDA or ROCm; the dataset
66
+ and captioning tools work without one.
67
+
68
+ Apple Silicon (MPS) is wired up but **has never been run on a Mac**: expect it to need fixes. It
69
+ trains in full precision only, so it wants a lot of memory. On a Mac, plain `pip install loracraft`
70
+ is enough, since the PyTorch build on PyPI includes MPS.
71
+
72
+ Install PyTorch **first**, from the index that matches your GPU, then LoraCraft. Which index that is
73
+ (CUDA version, ROCm, …) is listed at [pytorch.org](https://pytorch.org/get-started/locally/):
74
+
75
+ ```sh
76
+ python -m venv .venv # then activate it
77
+ pip install torch --index-url <index for your GPU>
78
+ pip install loracraft
79
+ ```
80
+
81
+ The order matters. LoraCraft accepts any PyTorch build, so the one you installed is kept; without
82
+ one, `pip install loracraft` brings the default build from PyPI, which on Windows cannot use the
83
+ GPU. If that happened, repeat the `pip install torch …` line with `--force-reinstall`. The training
84
+ page tells you when the installed PyTorch cannot train.
85
+
86
+ ## Run
87
+
88
+ ```sh
89
+ loracraft # http://127.0.0.1:8600
90
+ python -m loracraft --port 8700 # the same, on another port
91
+ ```
92
+
93
+ To use it as an app in a window of its own rather than in a browser tab, install the `app` extra:
94
+
95
+ ```sh
96
+ pip install "loracraft[app]"
97
+ loracraft --window
98
+ ```
99
+
100
+ The window uses the system's web view: WebView2 on Windows (part of Windows 11), WKWebView on
101
+ macOS; on Linux it needs GTK or Qt WebKit from the system packages, see the
102
+ [pywebview documentation](https://pywebview.flowrl.com/guide/installation.html). Closing the window
103
+ does not stop a training run in progress: it carries on, and LoraCraft picks it up when started
104
+ again.
105
+
106
+ User data (database, images, runs) lives in the per-user data directory, printed at startup:
107
+ `%LOCALAPPDATA%\loracraft` on Windows, `~/Library/Application Support/loracraft` on macOS,
108
+ `~/.local/share/loracraft` on Linux. Set `LORACRAFT_HOME` to keep it elsewhere.
109
+
110
+ ## Development
111
+
112
+ Requires [uv](https://docs.astral.sh/uv/) and Node.js.
113
+
114
+ ```sh
115
+ uv sync # Python environment, including PyTorch
116
+ cd web && npm install && npm run build
117
+ uv run loracraft
118
+ ```
119
+
120
+ `uv sync` installs the `torch-rocm` dependency group, which pins PyTorch to the AMD ROCm build for
121
+ Windows and RDNA2 cards (`device-gfx1030`). For another AMD card, change the `device-gfx…` names;
122
+ for another vendor, replace the group.
123
+
124
+ `npm run build` writes the web UI into `src/loracraft/web_dist/`, from where the server serves it.
125
+ For frontend work, run `npm run dev` in `web/` alongside the server and open http://localhost:5600.
126
+
127
+ To build the distributions (the web UI must be built first):
128
+
129
+ ```sh
130
+ uv build
131
+ ```
132
+
133
+ ## Training worker
134
+
135
+ A run is a directory containing `config.json` (see `trainer/config.py`):
136
+
137
+ ```sh
138
+ python -m loracraft.trainer <run_dir>
139
+ ```
140
+
141
+ It writes `events.jsonl`, `checkpoints/` and `samples/` into the same directory. Create a file
142
+ named `stop` there to stop gracefully. Checkpoints use kohya's key names and metadata, so they load
143
+ in ComfyUI and WebUI.
144
+
145
+ ## Tag dictionary
146
+
147
+ To validate Danbooru tags written by the vision model, put a tag list such as `danbooru.csv` (first
148
+ column: tag name) into `<workspace>/dictionaries/`. Without one, validation is skipped.
149
+
150
+ ## Tests
151
+
152
+ ```sh
153
+ uv run pytest
154
+ ```
155
+
156
+ ## Third-party code
157
+
158
+ `src/loracraft/vendor/kohya/` contains modified code from
159
+ [kohya-ss/sd-scripts](https://github.com/kohya-ss/sd-scripts), licensed under Apache-2.0. See the
160
+ README in that directory for the source commit and the list of changes.
@@ -0,0 +1,125 @@
1
+ # LoraCraft
2
+
3
+ A LoRA training workbench: manage datasets, captions, training runs and results in one place.
4
+ SDXL first.
5
+
6
+ ## What it does
7
+
8
+ - **Dataset**: import images with their captions, browse and filter by tag, edit tags one image at a
9
+ time or in bulk, spot missing captions and undersized images.
10
+ - **Auto-captioning**: a vision LLM (any OpenAI-compatible endpoint, local or hosted) writes captions
11
+ according to what the LoRA is for: a character, a style or a concept. Results are suggestions you
12
+ accept or discard; with a tag dictionary installed, invented tags are flagged or corrected.
13
+ - **Training**: a self-contained SDXL LoRA trainer with plain-language setup, a queue, live progress
14
+ and preview images after every round.
15
+ - **Results**: preview images of every round side by side, pick the best round, export it.
16
+
17
+ ## Layout
18
+
19
+ ```
20
+ src/loracraft/
21
+ server/ FastAPI backend: projects, dataset, auto-captioning, run queue
22
+ trainer/ SDXL LoRA trainer, runs as its own process
23
+ vendor/kohya/ code adapted from kohya-ss/sd-scripts (Apache-2.0)
24
+ web/ Svelte frontend
25
+ tests/
26
+ ```
27
+
28
+ ## Install
29
+
30
+ Requires Python 3.12. Training needs a GPU that PyTorch drives through CUDA or ROCm; the dataset
31
+ and captioning tools work without one.
32
+
33
+ Apple Silicon (MPS) is wired up but **has never been run on a Mac**: expect it to need fixes. It
34
+ trains in full precision only, so it wants a lot of memory. On a Mac, plain `pip install loracraft`
35
+ is enough, since the PyTorch build on PyPI includes MPS.
36
+
37
+ Install PyTorch **first**, from the index that matches your GPU, then LoraCraft. Which index that is
38
+ (CUDA version, ROCm, …) is listed at [pytorch.org](https://pytorch.org/get-started/locally/):
39
+
40
+ ```sh
41
+ python -m venv .venv # then activate it
42
+ pip install torch --index-url <index for your GPU>
43
+ pip install loracraft
44
+ ```
45
+
46
+ The order matters. LoraCraft accepts any PyTorch build, so the one you installed is kept; without
47
+ one, `pip install loracraft` brings the default build from PyPI, which on Windows cannot use the
48
+ GPU. If that happened, repeat the `pip install torch …` line with `--force-reinstall`. The training
49
+ page tells you when the installed PyTorch cannot train.
50
+
51
+ ## Run
52
+
53
+ ```sh
54
+ loracraft # http://127.0.0.1:8600
55
+ python -m loracraft --port 8700 # the same, on another port
56
+ ```
57
+
58
+ To use it as an app in a window of its own rather than in a browser tab, install the `app` extra:
59
+
60
+ ```sh
61
+ pip install "loracraft[app]"
62
+ loracraft --window
63
+ ```
64
+
65
+ The window uses the system's web view: WebView2 on Windows (part of Windows 11), WKWebView on
66
+ macOS; on Linux it needs GTK or Qt WebKit from the system packages, see the
67
+ [pywebview documentation](https://pywebview.flowrl.com/guide/installation.html). Closing the window
68
+ does not stop a training run in progress: it carries on, and LoraCraft picks it up when started
69
+ again.
70
+
71
+ User data (database, images, runs) lives in the per-user data directory, printed at startup:
72
+ `%LOCALAPPDATA%\loracraft` on Windows, `~/Library/Application Support/loracraft` on macOS,
73
+ `~/.local/share/loracraft` on Linux. Set `LORACRAFT_HOME` to keep it elsewhere.
74
+
75
+ ## Development
76
+
77
+ Requires [uv](https://docs.astral.sh/uv/) and Node.js.
78
+
79
+ ```sh
80
+ uv sync # Python environment, including PyTorch
81
+ cd web && npm install && npm run build
82
+ uv run loracraft
83
+ ```
84
+
85
+ `uv sync` installs the `torch-rocm` dependency group, which pins PyTorch to the AMD ROCm build for
86
+ Windows and RDNA2 cards (`device-gfx1030`). For another AMD card, change the `device-gfx…` names;
87
+ for another vendor, replace the group.
88
+
89
+ `npm run build` writes the web UI into `src/loracraft/web_dist/`, from where the server serves it.
90
+ For frontend work, run `npm run dev` in `web/` alongside the server and open http://localhost:5600.
91
+
92
+ To build the distributions (the web UI must be built first):
93
+
94
+ ```sh
95
+ uv build
96
+ ```
97
+
98
+ ## Training worker
99
+
100
+ A run is a directory containing `config.json` (see `trainer/config.py`):
101
+
102
+ ```sh
103
+ python -m loracraft.trainer <run_dir>
104
+ ```
105
+
106
+ It writes `events.jsonl`, `checkpoints/` and `samples/` into the same directory. Create a file
107
+ named `stop` there to stop gracefully. Checkpoints use kohya's key names and metadata, so they load
108
+ in ComfyUI and WebUI.
109
+
110
+ ## Tag dictionary
111
+
112
+ To validate Danbooru tags written by the vision model, put a tag list such as `danbooru.csv` (first
113
+ column: tag name) into `<workspace>/dictionaries/`. Without one, validation is skipped.
114
+
115
+ ## Tests
116
+
117
+ ```sh
118
+ uv run pytest
119
+ ```
120
+
121
+ ## Third-party code
122
+
123
+ `src/loracraft/vendor/kohya/` contains modified code from
124
+ [kohya-ss/sd-scripts](https://github.com/kohya-ss/sd-scripts), licensed under Apache-2.0. See the
125
+ README in that directory for the source commit and the list of changes.
@@ -0,0 +1,13 @@
1
+ """Build hook: a wheel or sdist must contain the built web UI."""
2
+
3
+ from pathlib import Path
4
+
5
+ from hatchling.builders.hooks.plugin.interface import BuildHookInterface
6
+
7
+
8
+ class RequireWebUI(BuildHookInterface):
9
+ def initialize(self, version: str, build_data: dict) -> None:
10
+ if version == "editable":
11
+ return # a development install serves whatever is there, or the API alone
12
+ if not Path(self.root, "src", "loracraft", "web_dist", "index.html").is_file():
13
+ raise RuntimeError("The web UI is not built: run `npm install && npm run build` in web/ first.")
@@ -0,0 +1,113 @@
1
+ [project]
2
+ name = "loracraft"
3
+ version = "0.1.0"
4
+ description = "LoRA training workbench with dataset, run and result management"
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE", "src/loracraft/vendor/kohya/LICENSE"]
8
+ authors = [{ name = "An Long" }]
9
+ keywords = ["lora", "sdxl", "stable-diffusion", "training", "dataset"]
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Environment :: Web Environment",
13
+ "Environment :: GPU",
14
+ "Intended Audience :: End Users/Desktop",
15
+ "Programming Language :: Python :: 3.12",
16
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
17
+ ]
18
+ requires-python = ">=3.12,<3.13"
19
+ dependencies = [
20
+ # Any build: which one can use the GPU depends on the machine, so the user installs theirs
21
+ # first, from the index of their choice (see README), and this requirement is then already
22
+ # met. Otherwise the default PyPI build is installed, which on Windows is CPU-only.
23
+ "torch>=2.4",
24
+ "diffusers>=0.35",
25
+ "transformers>=5.0",
26
+ "accelerate>=1.10",
27
+ "safetensors>=0.6",
28
+ "pillow>=11",
29
+ "numpy>=2",
30
+ "fastapi>=0.118",
31
+ "uvicorn[standard]>=0.37",
32
+ "pydantic>=2.11",
33
+ "httpx>=0.28",
34
+ "prodigyopt>=1.1.2",
35
+ "python-multipart>=0.0.33",
36
+ ]
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/aisk/loracraft"
40
+ Issues = "https://github.com/aisk/loracraft/issues"
41
+
42
+ [project.optional-dependencies]
43
+ # `loracraft --window`: the UI in a window of its own, through the system's web view.
44
+ app = ["pywebview>=5"]
45
+
46
+ [project.scripts]
47
+ loracraft = "loracraft.server.app:main"
48
+
49
+ [dependency-groups]
50
+ dev = ["pytest>=8", "ruff>=0.13", "loracraft[app]"]
51
+ # The PyTorch build used for development: AMD ROCm (TheRock) multi-arch wheels for an RDNA2 card
52
+ # (gfx1030) on Windows. Not part of the published package.
53
+ torch-rocm = [
54
+ "torch[device-gfx1030]==2.13.0+rocm10.1.0",
55
+ "torchvision[device-gfx1030]==0.28.0+rocm10.1.0",
56
+ # Runtime packages torch pulls in. They are listed here only so that
57
+ # [tool.uv.sources] can pin them to the AMD index; PyPI carries placeholder
58
+ # packages under the same names.
59
+ "rocm[libraries]==10.1.0",
60
+ "rocm-bootstrap",
61
+ "rocm-sdk-core==10.1.0",
62
+ "rocm-sdk-libraries==10.1.0",
63
+ "rocm-sdk-device-gfx1030==10.1.0",
64
+ "amd-torch-device-gfx1030==2.13.0+rocm10.1.0",
65
+ "amd-torchvision-device-gfx1030==0.28.0+rocm10.1.0",
66
+ ]
67
+
68
+ [build-system]
69
+ requires = ["hatchling"]
70
+ build-backend = "hatchling.build"
71
+
72
+ [tool.hatch.build.targets.wheel]
73
+ packages = ["src/loracraft"]
74
+
75
+ [tool.hatch.build]
76
+ # The built web UI is git-ignored, so it has to be named to get into the distributions.
77
+ artifacts = ["src/loracraft/web_dist/**"]
78
+
79
+ # Refuses to build a distribution without the web UI (see hatch_build.py).
80
+ [tool.hatch.build.hooks.custom]
81
+
82
+ [tool.uv]
83
+ default-groups = ["dev", "torch-rocm"]
84
+ # The ROCm wheels below are only wired up for Windows so far.
85
+ environments = ["sys_platform == 'win32'"]
86
+ # The index metadata for torch lists the Linux-only triton build; drop it on Windows.
87
+ override-dependencies = ["triton; sys_platform == 'linux'"]
88
+
89
+ [[tool.uv.index]]
90
+ name = "amd-rocm"
91
+ url = "https://stable.repo.amd.com/rocm/whl-next/"
92
+ explicit = true
93
+
94
+ [tool.uv.sources]
95
+ torch = { index = "amd-rocm" }
96
+ torchvision = { index = "amd-rocm" }
97
+ rocm = { index = "amd-rocm" }
98
+ rocm-bootstrap = { index = "amd-rocm" }
99
+ rocm-sdk-core = { index = "amd-rocm" }
100
+ rocm-sdk-libraries = { index = "amd-rocm" }
101
+ rocm-sdk-device-gfx1030 = { index = "amd-rocm" }
102
+ amd-torch-device-gfx1030 = { index = "amd-rocm" }
103
+ amd-torchvision-device-gfx1030 = { index = "amd-rocm" }
104
+
105
+ [tool.ruff]
106
+ line-length = 120
107
+ extend-exclude = ["src/loracraft/vendor"]
108
+
109
+ [tool.ruff.lint]
110
+ select = ["E", "F", "I", "B"]
111
+
112
+ [tool.ruff.lint.flake8-bugbear]
113
+ extend-immutable-calls = ["fastapi.Depends"]
@@ -0,0 +1 @@
1
+ """LoraCraft: LoRA training workbench."""
@@ -0,0 +1,6 @@
1
+ """`python -m loracraft` starts the server, like the `loracraft` command."""
2
+
3
+ from .server.app import main
4
+
5
+ if __name__ == "__main__":
6
+ main()