Spaces:
Running
on
Zero
Running
on
Zero
Upload 71 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +6 -0
- LICENSE +201 -0
- README.md +196 -14
- assets/repo_figures/Picture1.jpg +3 -0
- assets/repo_figures/Picture2.jpg +0 -0
- assets/repo_figures/Picture3.jpg +0 -0
- assets/repo_figures/Picture4.jpg +3 -0
- assets/repo_figures/Picture5.jpg +3 -0
- assets/repo_figures/Picture6.jpg +0 -0
- assets/repo_figures/Picture7.jpg +3 -0
- assets/repo_figures/Picture8.jpg +3 -0
- assets/repo_figures/examples/edit/art_batman.jpg +0 -0
- assets/repo_figures/examples/edit/art_mari.jpg +0 -0
- assets/repo_figures/examples/edit/boy.jpg +0 -0
- assets/repo_figures/examples/edit/cartoon_ein.jpg +0 -0
- assets/repo_figures/examples/edit/cartoon_herry.jpg +0 -0
- assets/repo_figures/examples/edit/hiking.jpg +0 -0
- assets/repo_figures/examples/edit/horse.jpg +0 -0
- assets/repo_figures/examples/edit/nobel_Biden.jpg +0 -0
- assets/repo_figures/examples/edit/nobel_Trump.jpg +0 -0
- assets/repo_figures/examples/source/art.jpg +0 -0
- assets/repo_figures/examples/source/boy.jpg +0 -0
- assets/repo_figures/examples/source/cartoon.jpg +0 -0
- assets/repo_figures/examples/source/hiking.jpg +0 -0
- assets/repo_figures/examples/source/horse.jpg +0 -0
- assets/repo_figures/examples/source/nobel.jpg +0 -0
- model_cards/FLUX.1-dev.md +46 -0
- model_cards/FLUX.1-schnell.md +41 -0
- model_licenses/LICENSE-FLUX1-dev +42 -0
- model_licenses/LICENSE-FLUX1-schnell +54 -0
- pyproject.toml +97 -0
- setup.py +3 -0
- src/edit.py +248 -0
- src/examples/edit/boy.jpg +0 -0
- src/examples/edit/hiking.jpg +0 -0
- src/examples/edit/horse.jpg +0 -0
- src/examples/source/art.jpg +3 -0
- src/examples/source/boy.jpg +0 -0
- src/examples/source/cartoon.jpg +0 -0
- src/examples/source/hiking.jpg +0 -0
- src/examples/source/horse.jpg +0 -0
- src/examples/source/nobel.jpg +0 -0
- src/flux/__init__.py +11 -0
- src/flux/__main__.py +4 -0
- src/flux/__pycache__/__init__.cpython-310.pyc +0 -0
- src/flux/__pycache__/math.cpython-310.pyc +0 -0
- src/flux/__pycache__/math.cpython-38.pyc +0 -0
- src/flux/__pycache__/model.cpython-310.pyc +0 -0
- src/flux/__pycache__/sampling.cpython-310.pyc +0 -0
- src/flux/__pycache__/util.cpython-310.pyc +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
assets/repo_figures/Picture1.jpg filter=lfs diff=lfs merge=lfs -text
|
37 |
+
assets/repo_figures/Picture4.jpg filter=lfs diff=lfs merge=lfs -text
|
38 |
+
assets/repo_figures/Picture5.jpg filter=lfs diff=lfs merge=lfs -text
|
39 |
+
assets/repo_figures/Picture7.jpg filter=lfs diff=lfs merge=lfs -text
|
40 |
+
assets/repo_figures/Picture8.jpg filter=lfs diff=lfs merge=lfs -text
|
41 |
+
src/examples/source/art.jpg filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
@@ -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 [yyyy] [name of copyright owner]
|
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.
|
README.md
CHANGED
@@ -1,14 +1,196 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div align="center">
|
2 |
+
|
3 |
+
# Taming Rectified Flow for Inversion and Editing
|
4 |
+
|
5 |
+
[Jiangshan Wang](https://scholar.google.com/citations?user=HoKoCv0AAAAJ&hl=en)<sup>1,2</sup>, [Junfu Pu](https://pujunfu.github.io/)<sup>2</sup>, [Zhongang Qi](https://scholar.google.com/citations?hl=en&user=zJvrrusAAAAJ&view_op=list_works&sortby=pubdate)<sup>2</sup>, [Jiayi Guo](https://www.jiayiguo.net)<sup>1</sup>, [Yue Ma](https://mayuelala.github.io/)<sup>3</sup>, <br> [Nisha Huang](https://scholar.google.com/citations?user=wTmPkSsAAAAJ&hl=en)<sup>1</sup>, [Yuxin Chen](https://scholar.google.com/citations?hl=en&user=dEm4OKAAAAAJ)<sup>2</sup>, [Xiu Li](https://scholar.google.com/citations?user=Xrh1OIUAAAAJ&hl=en&oi=ao)<sup>1</sup>, [Ying Shan](https://scholar.google.com/citations?hl=en&user=4oXBp9UAAAAJ&view_op=list_works&sortby=pubdate)<sup>2</sup>
|
6 |
+
|
7 |
+
<sup>1</sup> Tsinghua University, <sup>2</sup> Tencent ARC Lab, <sup>3</sup> HKUST
|
8 |
+
|
9 |
+
[![arXiv](https://img.shields.io/badge/arXiv-RFSolverEdit-b31b1b.svg)](https://arxiv.org/abs/2411.04746)
|
10 |
+
<a href='https://rf-solver-edit.github.io/'><img src='https://img.shields.io/badge/Project-Page-Green'></a>
|
11 |
+
|
12 |
+
</div>
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
<p>
|
19 |
+
We propose <strong>RF-Solver</strong> to solve the rectified flow ODE with less error, thus enhancing both sampling quality and inversion-reconstruction accuracy for rectified-flow-based generative models. Furthermore, we propose <strong>RF-Edit</strong> to leverage the <strong>RF-Solver</strong> for image and video editing tasks. Our methods achieve impressive performance on various tasks, including text-to-image generation, image/video inversion, and image/video editing.
|
20 |
+
</p>
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
<p align="center">
|
25 |
+
<img src="assets/repo_figures/Picture1.jpg" width="1080px"/>
|
26 |
+
</p>
|
27 |
+
|
28 |
+
# 🔥 News
|
29 |
+
- [2024.11.18] More examples for style transfer are available!
|
30 |
+
- [2024.11.18] Gradio Demo for image editing is available!
|
31 |
+
- [2024.11.11] The homepage of the project is available!
|
32 |
+
- [2024.11.08] Code for image editing is released!
|
33 |
+
- [2024.11.08] Paper released!
|
34 |
+
|
35 |
+
# 👨💻 ToDo
|
36 |
+
- ☑️ Release the gradio demo
|
37 |
+
- ☑️ Release scripts to for more image editing cases
|
38 |
+
- ☐ Release the code for video editing
|
39 |
+
|
40 |
+
|
41 |
+
# 📖 Method
|
42 |
+
## RF-Solver
|
43 |
+
<p>
|
44 |
+
<img src="assets/repo_figures/Picture2.jpg" width="1080px"/>
|
45 |
+
We derive the exact formulation of the solution for Rectified Flow ODE. The non-linear part in this solution is processed by Taylor Expansion. Through higher order expansion, the approximation error in the solution is significantly reduced, thus achieving impressive performance on both text-to-image sampling and image/video inversion.
|
46 |
+
</p>
|
47 |
+
|
48 |
+
## RF-Edit
|
49 |
+
<p>
|
50 |
+
<img src="assets/repo_figures/Picture3.jpg" width="1080px"/>
|
51 |
+
Based on RF-Solver, we further propose the RF-Edit for image and video editing. RF-Edit framework leverages the features from inversion in the denoising process, which enables high-quality editing while preserving the structual information of source image/video. RF-Edit contains two sub-modules, espectively for image editing and video editing.
|
52 |
+
</p>
|
53 |
+
|
54 |
+
# 🛠️ Code Setup
|
55 |
+
The environment of our code is the same as FLUX, you can refer to the [official repo](https://github.com/black-forest-labs/flux/tree/main) of FLUX, or running the following command to construct the environment.
|
56 |
+
```
|
57 |
+
conda create --name RF-Solver-Edit python=3.10
|
58 |
+
conda activate RF-Solver-Edit
|
59 |
+
pip install -e ".[all]"
|
60 |
+
```
|
61 |
+
# 🚀 Examples for Image Editing
|
62 |
+
We have provided several scripts to reproduce the results in the paper, mainly including 3 types of editing: Stylization, Adding, Replacing. We suggest to run the experiment on a single A100 GPU.
|
63 |
+
|
64 |
+
## Stylization
|
65 |
+
<table class="center">
|
66 |
+
<tr>
|
67 |
+
<td width=10% align="center">Ref Style</td>
|
68 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/source/nobel.jpg" raw=true></td>
|
69 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/source/art.jpg" raw=true></td>
|
70 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/source/cartoon.jpg" raw=true></td>
|
71 |
+
</tr>
|
72 |
+
<tr>
|
73 |
+
<td width="10%" align="center">Editing Scripts</td>
|
74 |
+
<td width="30%" align="center"><a href="src/run_nobel_trump.sh">Trump</a></td>
|
75 |
+
<td width="30%" align="center"><a href="src/run_art_mari.sh"> Marilyn Monroe</a></td>
|
76 |
+
<td width="30%" align="center"><a href="src/run_cartoon_ein.sh">Einstein</a></td>
|
77 |
+
</tr>
|
78 |
+
<tr>
|
79 |
+
<td width=10% align="center">Edtied image</td>
|
80 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/edit/nobel_Trump.jpg" raw=true></td>
|
81 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/edit/art_mari.jpg" raw=true></td>
|
82 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/edit/cartoon_ein.jpg" raw=true></td>
|
83 |
+
</tr>
|
84 |
+
|
85 |
+
<tr>
|
86 |
+
<td width="10%" align="center">Editing Scripts</td>
|
87 |
+
<td width="30%" align="center"><a href="src/run_nobel_biden.sh">Biden</a></td>
|
88 |
+
<td width="30%" align="center"><a href="src/run_art_batman.sh">Batman</a></td>
|
89 |
+
<td width="30%" align="center"><a href="src/run_cartoon_herry.sh">Herry Potter</a></td>
|
90 |
+
</tr>
|
91 |
+
<tr>
|
92 |
+
<td width=10% align="center">Edtied image</td>
|
93 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/edit/nobel_Biden.jpg" raw=true></td>
|
94 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/edit/art_batman.jpg" raw=true></td>
|
95 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/edit/cartoon_herry.jpg" raw=true></td>
|
96 |
+
</tr>
|
97 |
+
</table>
|
98 |
+
|
99 |
+
## Adding & Replacing
|
100 |
+
<table class="center">
|
101 |
+
<tr>
|
102 |
+
<td width=10% align="center">Source image</td>
|
103 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/source/hiking.jpg" raw=true></td>
|
104 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/source/horse.jpg" raw=true></td>
|
105 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/source/boy.jpg" raw=true></td>
|
106 |
+
</tr>
|
107 |
+
<tr>
|
108 |
+
<td width="10%" align="center">Editing Scripts</td>
|
109 |
+
<td width="30%" align="center"><a href="src/run_boy.sh">+ hiking stick</a></td>
|
110 |
+
<td width="30%" align="center"><a href="src/run_horse.sh">horse -> camel</a></td>
|
111 |
+
<td width="30%" align="center"><a href="src/run_boy.sh">+ dog</a></td>
|
112 |
+
</tr>
|
113 |
+
<tr>
|
114 |
+
<td width=10% align="center">Edtied image</td>
|
115 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/edit/hiking.jpg" raw=true></td>
|
116 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/edit/horse.jpg" raw=true></td>
|
117 |
+
<td width=30% align="center"><img src="assets/repo_figures/examples/edit/boy.jpg" raw=true></td>
|
118 |
+
</tr>
|
119 |
+
|
120 |
+
</table>
|
121 |
+
|
122 |
+
|
123 |
+
# 🪄 Edit Your Own Image
|
124 |
+
|
125 |
+
## Gradio Demo
|
126 |
+
We privide the gradio demo for image editing. Run the following command:
|
127 |
+
```
|
128 |
+
cd src
|
129 |
+
python gradio_demo.py
|
130 |
+
```
|
131 |
+
Here is an example for using the gradio demo to edit an image! Note that here "Number of inject steps" means the steps of feature sharing in RF-Edit, which is highly related to the quality of edited results. We suggest to tune this parameter, selecting the results with best visual quality.
|
132 |
+
<div style="text-align: center;">
|
133 |
+
<img src="assets/repo_figures/Picture7.jpg" style="width:100%; display: block; margin: 0 auto;" />
|
134 |
+
</div>
|
135 |
+
|
136 |
+
|
137 |
+
## Command Line
|
138 |
+
You can also run the following scripts to edit your own image.
|
139 |
+
```
|
140 |
+
cd src
|
141 |
+
python edit.py --source_prompt [describe the content of your image or leaves it as null] \
|
142 |
+
--target_prompt [describe your editing requirements] \
|
143 |
+
--guidance 2 \
|
144 |
+
--source_img_dir [the path of your source image] \
|
145 |
+
--num_steps 30 \
|
146 |
+
--inject [typically set to a number between 2 to 8] \
|
147 |
+
--name 'flux-dev' --offload \
|
148 |
+
--output_dir [output path]
|
149 |
+
```
|
150 |
+
Similarly, The ```--inject``` refers to the steps of feature sharing in RF-Edit, which is highly related to the performance of editing.
|
151 |
+
|
152 |
+
|
153 |
+
|
154 |
+
# 🖼️ Gallery
|
155 |
+
## Inversion and Reconstruction
|
156 |
+
|
157 |
+
<p align="center">
|
158 |
+
<img src="assets/repo_figures/Picture4.jpg" width="1080px"/>
|
159 |
+
</p>
|
160 |
+
|
161 |
+
## Image Stylization
|
162 |
+
|
163 |
+
<p align="center">
|
164 |
+
<img src="assets/repo_figures/Picture8.jpg" width="1080px"/>
|
165 |
+
</p>
|
166 |
+
|
167 |
+
## Image Editing
|
168 |
+
|
169 |
+
<p align="center">
|
170 |
+
<img src="assets/repo_figures/Picture5.jpg" width="1080px"/>
|
171 |
+
</p>
|
172 |
+
|
173 |
+
## Video Editing
|
174 |
+
|
175 |
+
<p align="center">
|
176 |
+
<img src="assets/repo_figures/Picture6.jpg" width="1080px"/>
|
177 |
+
</p>
|
178 |
+
|
179 |
+
# 🖋️ Citation
|
180 |
+
|
181 |
+
If you find our work helpful, please **star 🌟** this repo and **cite 📑** our paper. Thanks for your support!
|
182 |
+
|
183 |
+
```
|
184 |
+
@article{wang2024taming,
|
185 |
+
title={Taming Rectified Flow for Inversion and Editing},
|
186 |
+
author={Wang, Jiangshan and Pu, Junfu and Qi, Zhongang and Guo, Jiayi and Ma, Yue and Huang, Nisha and Chen, Yuxin and Li, Xiu and Shan, Ying},
|
187 |
+
journal={arXiv preprint arXiv:2411.04746},
|
188 |
+
year={2024}
|
189 |
+
}
|
190 |
+
```
|
191 |
+
|
192 |
+
# Acknowledgements
|
193 |
+
We thank [FLUX](https://github.com/black-forest-labs/flux/tree/main) for their clean codebase.
|
194 |
+
|
195 |
+
# Contact
|
196 |
+
The code in this repository is still being reorganized. Errors that may arise during the organizing process could lead to code malfunctions or discrepancies from the original research results. If you have any questions or concerns, please send email to wjs23@mails.tsinghua.edu.cn.
|
assets/repo_figures/Picture1.jpg
ADDED
Git LFS Details
|
assets/repo_figures/Picture2.jpg
ADDED
assets/repo_figures/Picture3.jpg
ADDED
assets/repo_figures/Picture4.jpg
ADDED
Git LFS Details
|
assets/repo_figures/Picture5.jpg
ADDED
Git LFS Details
|
assets/repo_figures/Picture6.jpg
ADDED
assets/repo_figures/Picture7.jpg
ADDED
Git LFS Details
|
assets/repo_figures/Picture8.jpg
ADDED
Git LFS Details
|
assets/repo_figures/examples/edit/art_batman.jpg
ADDED
assets/repo_figures/examples/edit/art_mari.jpg
ADDED
assets/repo_figures/examples/edit/boy.jpg
ADDED
assets/repo_figures/examples/edit/cartoon_ein.jpg
ADDED
assets/repo_figures/examples/edit/cartoon_herry.jpg
ADDED
assets/repo_figures/examples/edit/hiking.jpg
ADDED
assets/repo_figures/examples/edit/horse.jpg
ADDED
assets/repo_figures/examples/edit/nobel_Biden.jpg
ADDED
assets/repo_figures/examples/edit/nobel_Trump.jpg
ADDED
assets/repo_figures/examples/source/art.jpg
ADDED
assets/repo_figures/examples/source/boy.jpg
ADDED
assets/repo_figures/examples/source/cartoon.jpg
ADDED
assets/repo_figures/examples/source/hiking.jpg
ADDED
assets/repo_figures/examples/source/horse.jpg
ADDED
assets/repo_figures/examples/source/nobel.jpg
ADDED
model_cards/FLUX.1-dev.md
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
![FLUX.1 [dev] Grid](../assets/dev_grid.jpg)
|
2 |
+
|
3 |
+
`FLUX.1 [dev]` is a 12 billion parameter rectified flow transformer capable of generating images from text descriptions.
|
4 |
+
For more information, please read our [blog post](https://blackforestlabs.ai/announcing-black-forest-labs/).
|
5 |
+
|
6 |
+
# Key Features
|
7 |
+
1. Cutting-edge output quality, second only to our state-of-the-art model `FLUX.1 [pro]`.
|
8 |
+
2. Competitive prompt following, matching the performance of closed source alternatives.
|
9 |
+
3. Trained using guidance distillation, making `FLUX.1 [dev]` more efficient.
|
10 |
+
4. Open weights to drive new scientific research, and empower artists to develop innovative workflows.
|
11 |
+
5. Generated outputs can be used for personal, scientific, and commercial purposes, as described in the [flux-1-dev-non-commercial-license](./licence.md).
|
12 |
+
|
13 |
+
# Usage
|
14 |
+
We provide a reference implementation of `FLUX.1 [dev]`, as well as sampling code, in a dedicated [github repository](https://github.com/black-forest-labs/flux).
|
15 |
+
Developers and creatives looking to build on top of `FLUX.1 [dev]` are encouraged to use this as a starting point.
|
16 |
+
|
17 |
+
## API Endpoints
|
18 |
+
The FLUX.1 models are also available via API from the following sources
|
19 |
+
1. [bfl.ml](https://docs.bfl.ml/) (currently `FLUX.1 [pro]`)
|
20 |
+
2. [replicate.com](https://replicate.com/collections/flux)
|
21 |
+
3. [fal.ai](https://fal.ai/models/fal-ai/flux/dev)
|
22 |
+
|
23 |
+
## ComfyUI
|
24 |
+
`FLUX.1 [dev]` is also available in [Comfy UI](https://github.com/comfyanonymous/ComfyUI) for local inference with a node-based workflow.
|
25 |
+
|
26 |
+
---
|
27 |
+
# Limitations
|
28 |
+
- This model is not intended or able to provide factual information.
|
29 |
+
- As a statistical model this checkpoint might amplify existing societal biases.
|
30 |
+
- The model may fail to generate output that matches the prompts.
|
31 |
+
- Prompt following is heavily influenced by the prompting-style.
|
32 |
+
|
33 |
+
# Out-of-Scope Use
|
34 |
+
The model and its derivatives may not be used
|
35 |
+
|
36 |
+
- In any way that violates any applicable national, federal, state, local or international law or regulation.
|
37 |
+
- For the purpose of exploiting, harming or attempting to exploit or harm minors in any way; including but not limited to the solicitation, creation, acquisition, or dissemination of child exploitative content.
|
38 |
+
- To generate or disseminate verifiably false information and/or content with the purpose of harming others.
|
39 |
+
- To generate or disseminate personal identifiable information that can be used to harm an individual.
|
40 |
+
- To harass, abuse, threaten, stalk, or bully individuals or groups of individuals.
|
41 |
+
- To create non-consensual nudity or illegal pornographic content.
|
42 |
+
- For fully automated decision making that adversely impacts an individual's legal rights or otherwise creates or modifies a binding, enforceable obligation.
|
43 |
+
- Generating or facilitating large-scale disinformation campaigns.
|
44 |
+
|
45 |
+
# License
|
46 |
+
This model falls under the [`FLUX.1 [dev]` Non-Commercial License](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md).
|
model_cards/FLUX.1-schnell.md
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
![FLUX.1 [schnell] Grid](../assets/schnell_grid.jpg)
|
2 |
+
|
3 |
+
`FLUX.1 [schnell]` is a 12 billion parameter rectified flow transformer capable of generating images from text descriptions.
|
4 |
+
For more information, please read our [blog post](https://blackforestlabs.ai/announcing-black-forest-labs/).
|
5 |
+
|
6 |
+
# Key Features
|
7 |
+
1. Cutting-edge output quality and competitive prompt following, matching the performance of closed source alternatives.
|
8 |
+
2. Trained using latent adversarial diffusion distillation, `FLUX.1 [schnell]` can generate high-quality images in only 1 to 4 steps.
|
9 |
+
3. Released under the `apache-2.0` licence, the model can be used for personal, scientific, and commercial purposes.
|
10 |
+
|
11 |
+
# Usage
|
12 |
+
We provide a reference implementation of `FLUX.1 [schnell]`, as well as sampling code, in a dedicated [github repository](https://github.com/black-forest-labs/flux).
|
13 |
+
Developers and creatives looking to build on top of `FLUX.1 [schnell]` are encouraged to use this as a starting point.
|
14 |
+
|
15 |
+
## API Endpoints
|
16 |
+
The FLUX.1 models are also available via API from the following sources
|
17 |
+
1. [bfl.ml](https://docs.bfl.ml/) (currently `FLUX.1 [pro]`)
|
18 |
+
2. [replicate.com](https://replicate.com/collections/flux)
|
19 |
+
3. [fal.ai](https://fal.ai/models/fal-ai/flux/schnell)
|
20 |
+
|
21 |
+
## ComfyUI
|
22 |
+
`FLUX.1 [schnell]` is also available in [Comfy UI](https://github.com/comfyanonymous/ComfyUI) for local inference with a node-based workflow.
|
23 |
+
|
24 |
+
---
|
25 |
+
# Limitations
|
26 |
+
- This model is not intended or able to provide factual information.
|
27 |
+
- As a statistical model this checkpoint might amplify existing societal biases.
|
28 |
+
- The model may fail to generate output that matches the prompts.
|
29 |
+
- Prompt following is heavily influenced by the prompting-style.
|
30 |
+
|
31 |
+
# Out-of-Scope Use
|
32 |
+
The model and its derivatives may not be used
|
33 |
+
|
34 |
+
- In any way that violates any applicable national, federal, state, local or international law or regulation.
|
35 |
+
- For the purpose of exploiting, harming or attempting to exploit or harm minors in any way; including but not limited to the solicitation, creation, acquisition, or dissemination of child exploitative content.
|
36 |
+
- To generate or disseminate verifiably false information and/or content with the purpose of harming others.
|
37 |
+
- To generate or disseminate personal identifiable information that can be used to harm an individual.
|
38 |
+
- To harass, abuse, threaten, stalk, or bully individuals or groups of individuals.
|
39 |
+
- To create non-consensual nudity or illegal pornographic content.
|
40 |
+
- For fully automated decision making that adversely impacts an individual's legal rights or otherwise creates or modifies a binding, enforceable obligation.
|
41 |
+
- Generating or facilitating large-scale disinformation campaigns.
|
model_licenses/LICENSE-FLUX1-dev
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FLUX.1 [dev] Non-Commercial License
|
2 |
+
Black Forest Labs, Inc. (“we” or “our” or “Company”) is pleased to make available the weights, parameters and inference code for the FLUX.1 [dev] Model (as defined below) freely available for your non-commercial and non-production use as set forth in this FLUX.1 [dev] Non-Commercial License (“License”). The “FLUX.1 [dev] Model” means the FLUX.1 [dev] text-to-image AI model and its elements which includes algorithms, software, checkpoints, parameters, source code (inference code, evaluation code, and if applicable, fine-tuning code) and any other materials associated with the FLUX.1 [dev] AI model made available by Company under this License, including if any, the technical documentation, manuals and instructions for the use and operation thereof (collectively, “FLUX.1 [dev] Model”).
|
3 |
+
By downloading, accessing, use, Distributing (as defined below), or creating a Derivative (as defined below) of the FLUX.1 [dev] Model, you agree to the terms of this License. If you do not agree to this License, then you do not have any rights to access, use, Distribute or create a Derivative of the FLUX.1 [dev] Model and you must immediately cease using the FLUX.1 [dev] Model. If you are agreeing to be bound by the terms of this License on behalf of your employer or other entity, you represent and warrant to us that you have full legal authority to bind your employer or such entity to this License. If you do not have the requisite authority, you may not accept the License or access the FLUX.1 [dev] Model on behalf of your employer or other entity.
|
4 |
+
1. Definitions. Capitalized terms used in this License but not defined herein have the following meanings:
|
5 |
+
a. “Derivative” means any (i) modified version of the FLUX.1 [dev] Model (including but not limited to any customized or fine-tuned version thereof), (ii) work based on the FLUX.1 [dev] Model, or (iii) any other derivative work thereof. For the avoidance of doubt, Outputs are not considered Derivatives under this License.
|
6 |
+
b. “Distribution” or “Distribute” or “Distributing” means providing or making available, by any means, a copy of the FLUX.1 [dev] Models and/or the Derivatives as the case may be.
|
7 |
+
c. “Non-Commercial Purpose” means any of the following uses, but only so far as you do not receive any direct or indirect payment arising from the use of the model or its output: (i) personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, or otherwise not directly or indirectly connected to any commercial activities, business operations, or employment responsibilities; (ii) use by commercial or for-profit entities for testing, evaluation, or non-commercial research and development in a non-production environment, (iii) use by any charitable organization for charitable purposes, or for testing or evaluation. For clarity, use for revenue-generating activity or direct interactions with or impacts on end users, or use to train, fine tune or distill other models for commercial use is not a Non-Commercial purpose.
|
8 |
+
d. “Outputs” means any content generated by the operation of the FLUX.1 [dev] Models or the Derivatives from a prompt (i.e., text instructions) provided by users. For the avoidance of doubt, Outputs do not include any components of a FLUX.1 [dev] Models, such as any fine-tuned versions of the FLUX.1 [dev] Models, the weights, or parameters.
|
9 |
+
e. “you” or “your” means the individual or entity entering into this License with Company.
|
10 |
+
2. License Grant.
|
11 |
+
a. License. Subject to your compliance with this License, Company grants you a non-exclusive, worldwide, non-transferable, non-sublicensable, revocable, royalty free and limited license to access, use, create Derivatives of, and Distribute the FLUX.1 [dev] Models solely for your Non-Commercial Purposes. The foregoing license is personal to you, and you may not assign or sublicense this License or any other rights or obligations under this License without Company’s prior written consent; any such assignment or sublicense will be void and will automatically and immediately terminate this License. Any restrictions set forth herein in regarding the FLUX.1 [dev] Model also applies to any Derivative you create or that are created on your behalf.
|
12 |
+
b. Non-Commercial Use Only. You may only access, use, Distribute, or creative Derivatives of or the FLUX.1 [dev] Model or Derivatives for Non-Commercial Purposes. If You want to use a FLUX.1 [dev] Model a Derivative for any purpose that is not expressly authorized under this License, such as for a commercial activity, you must request a license from Company, which Company may grant to you in Company’s sole discretion and which additional use may be subject to a fee, royalty or other revenue share. Please contact Company at the following e-mail address if you want to discuss such a license: info@blackforestlabs.ai.
|
13 |
+
c. Reserved Rights. The grant of rights expressly set forth in this License are the complete grant of rights to you in the FLUX.1 [dev] Model, and no other licenses are granted, whether by waiver, estoppel, implication, equity or otherwise. Company and its licensors reserve all rights not expressly granted by this License.
|
14 |
+
d. Outputs. We claim no ownership rights in and to the Outputs. You are solely responsible for the Outputs you generate and their subsequent uses in accordance with this License. You may use Output for any purpose (including for commercial purposes), except as expressly prohibited herein. You may not use the Output to train, fine-tune or distill a model that is competitive with the FLUX.1 [dev] Model.
|
15 |
+
3. Distribution. Subject to this License, you may Distribute copies of the FLUX.1 [dev] Model and/or Derivatives made by you, under the following conditions:
|
16 |
+
a. you must make available a copy of this License to third-party recipients of the FLUX.1 [dev] Models and/or Derivatives you Distribute, and specify that any rights to use the FLUX.1 [dev] Models and/or Derivatives shall be directly granted by Company to said third-party recipients pursuant to this License;
|
17 |
+
b. you must make prominently display the following notice alongside the Distribution of the FLUX.1 [dev] Model or Derivative (such as via a “Notice” text file distributed as part of such FLUX.1 [dev] Model or Derivative) (the “Attribution Notice”):
|
18 |
+
“The FLUX.1 [dev] Model is licensed by Black Forest Labs. Inc. under the FLUX.1 [dev] Non-Commercial License. Copyright Black Forest Labs. Inc.
|
19 |
+
IN NO EVENT SHALL BLACK FOREST LABS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH USE OF THIS MODEL.”
|
20 |
+
c. in the case of Distribution of Derivatives made by you, you must also include in the Attribution Notice a statement that you have modified the applicable FLUX.1 [dev] Model; and
|
21 |
+
d. in the case of Distribution of Derivatives made by you, any terms and conditions you impose on any third-party recipients relating to Derivatives made by or for you shall neither limit such third-party recipients’ use of the FLUX.1 [dev] Model or any Derivatives made by or for Company in accordance with this License nor conflict with any of its terms and conditions.
|
22 |
+
e. In the case of Distribution of Derivatives made by you, you must not misrepresent or imply, through any means, that the Derivatives made by or for you and/or any modified version of the FLUX.1 [dev] Model you Distribute under your name and responsibility is an official product of the Company or has been endorsed, approved or validated by the Company, unless you are authorized by Company to do so in writing.
|
23 |
+
4. Restrictions. You will not, and will not permit, assist or cause any third party to
|
24 |
+
a. use, modify, copy, reproduce, create Derivatives of, or Distribute the FLUX.1 [dev] Model (or any Derivative thereof, or any data produced by the FLUX.1 [dev] Model), in whole or in part, for (i) any commercial or production purposes, (ii) military purposes, (iii) purposes of surveillance, including any research or development relating to surveillance, (iv) biometric processing, (v) in any manner that infringes, misappropriates, or otherwise violates any third-party rights, or (vi) in any manner that violates any applicable law and violating any privacy or security laws, rules, regulations, directives, or governmental requirements (including the General Data Privacy Regulation (Regulation (EU) 2016/679), the California Consumer Privacy Act, and any and all laws governing the processing of biometric information), as well as all amendments and successor laws to any of the foregoing;
|
25 |
+
b. alter or remove copyright and other proprietary notices which appear on or in any portion of the FLUX.1 [dev] Model;
|
26 |
+
c. utilize any equipment, device, software, or other means to circumvent or remove any security or protection used by Company in connection with the FLUX.1 [dev] Model, or to circumvent or remove any usage restrictions, or to enable functionality disabled by FLUX.1 [dev] Model; or
|
27 |
+
d. offer or impose any terms on the FLUX.1 [dev] Model that alter, restrict, or are inconsistent with the terms of this License.
|
28 |
+
e. violate any applicable U.S. and non-U.S. export control and trade sanctions laws (“Export Laws”) in connection with your use or Distribution of any FLUX.1 [dev] Model;
|
29 |
+
f. directly or indirectly Distribute, export, or otherwise transfer FLUX.1 [dev] Model (a) to any individual, entity, or country prohibited by Export Laws; (b) to anyone on U.S. or non-U.S. government restricted parties lists; or (c) for any purpose prohibited by Export Laws, including nuclear, chemical or biological weapons, or missile technology applications; 3) use or download FLUX.1 [dev] Model if you or they are (a) located in a comprehensively sanctioned jurisdiction, (b) currently listed on any U.S. or non-U.S. restricted parties list, or (c) for any purpose prohibited by Export Laws; and (4) will not disguise your location through IP proxying or other methods.
|
30 |
+
5. DISCLAIMERS. THE FLUX.1 [dev] MODEL IS PROVIDED “AS IS” AND “WITH ALL FAULTS” WITH NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. COMPANY EXPRESSLY DISCLAIMS ALL REPRESENTATIONS AND WARRANTIES, EXPRESS OR IMPLIED, WHETHER BY STATUTE, CUSTOM, USAGE OR OTHERWISE AS TO ANY MATTERS RELATED TO THE FLUX.1 [dev] MODEL, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, SATISFACTORY QUALITY, OR NON-INFRINGEMENT. COMPANY MAKES NO WARRANTIES OR REPRESENTATIONS THAT THE FLUX.1 [dev] MODEL WILL BE ERROR FREE OR FREE OF VIRUSES OR OTHER HARMFUL COMPONENTS, OR PRODUCE ANY PARTICULAR RESULTS.
|
31 |
+
6. LIMITATION OF LIABILITY. TO THE FULLEST EXTENT PERMITTED BY LAW, IN NO EVENT WILL COMPANY BE LIABLE TO YOU OR YOUR EMPLOYEES, AFFILIATES, USERS, OFFICERS OR DIRECTORS (A) UNDER ANY THEORY OF LIABILITY, WHETHER BASED IN CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY, WARRANTY, OR OTHERWISE UNDER THIS LICENSE, OR (B) FOR ANY INDIRECT, CONSEQUENTIAL, EXEMPLARY, INCIDENTAL, PUNITIVE OR SPECIAL DAMAGES OR LOST PROFITS, EVEN IF COMPANY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THE FLUX.1 [dev] MODEL, ITS CONSTITUENT COMPONENTS, AND ANY OUTPUT (COLLECTIVELY, “MODEL MATERIALS”) ARE NOT DESIGNED OR INTENDED FOR USE IN ANY APPLICATION OR SITUATION WHERE FAILURE OR FAULT OF THE MODEL MATERIALS COULD REASONABLY BE ANTICIPATED TO LEAD TO SERIOUS INJURY OF ANY PERSON, INCLUDING POTENTIAL DISCRIMINATION OR VIOLATION OF AN INDIVIDUAL’S PRIVACY RIGHTS, OR TO SEVERE PHYSICAL, PROPERTY, OR ENVIRONMENTAL DAMAGE (EACH, A “HIGH-RISK USE”). IF YOU ELECT TO USE ANY OF THE MODEL MATERIALS FOR A HIGH-RISK USE, YOU DO SO AT YOUR OWN RISK. YOU AGREE TO DESIGN AND IMPLEMENT APPROPRIATE DECISION-MAKING AND RISK-MITIGATION PROCEDURES AND POLICIES IN CONNECTION WITH A HIGH-RISK USE SUCH THAT EVEN IF THERE IS A FAILURE OR FAULT IN ANY OF THE MODEL MATERIALS, THE SAFETY OF PERSONS OR PROPERTY AFFECTED BY THE ACTIVITY STAYS AT A LEVEL THAT IS REASONABLE, APPROPRIATE, AND LAWFUL FOR THE FIELD OF THE HIGH-RISK USE.
|
32 |
+
7. INDEMNIFICATION
|
33 |
+
|
34 |
+
You will indemnify, defend and hold harmless Company and our subsidiaries and affiliates, and each of our respective shareholders, directors, officers, employees, agents, successors, and assigns (collectively, the “Company Parties”) from and against any losses, liabilities, damages, fines, penalties, and expenses (including reasonable attorneys’ fees) incurred by any Company Party in connection with any claim, demand, allegation, lawsuit, proceeding, or investigation (collectively, “Claims”) arising out of or related to (a) your access to or use of the FLUX.1 [dev] Model (as well as any Output, results or data generated from such access or use), including any High-Risk Use (defined below); (b) your violation of this License; or (c) your violation, misappropriation or infringement of any rights of another (including intellectual property or other proprietary rights and privacy rights). You will promptly notify the Company Parties of any such Claims, and cooperate with Company Parties in defending such Claims. You will also grant the Company Parties sole control of the defense or settlement, at Company’s sole option, of any Claims. This indemnity is in addition to, and not in lieu of, any other indemnities or remedies set forth in a written agreement between you and Company or the other Company Parties.
|
35 |
+
8. Termination; Survival.
|
36 |
+
a. This License will automatically terminate upon any breach by you of the terms of this License.
|
37 |
+
b. We may terminate this License, in whole or in part, at any time upon notice (including electronic) to you.
|
38 |
+
c. If You initiate any legal action or proceedings against Company or any other entity (including a cross-claim or counterclaim in a lawsuit), alleging that the FLUX.1 [dev] Model or any Derivative, or any part thereof, infringe upon intellectual property or other rights owned or licensable by you, then any licenses granted to you under this License will immediately terminate as of the date such legal action or claim is filed or initiated.
|
39 |
+
d. Upon termination of this License, you must cease all use, access or Distribution of the FLUX.1 [dev] Model and any Derivatives. The following sections survive termination of this License 2(c), 2(d), 4-11.
|
40 |
+
9. Third Party Materials. The FLUX.1 [dev] Model may contain third-party software or other components (including free and open source software) (all of the foregoing, “Third Party Materials”), which are subject to the license terms of the respective third-party licensors. Your dealings or correspondence with third parties and your use of or interaction with any Third Party Materials are solely between you and the third party. Company does not control or endorse, and makes no representations or warranties regarding, any Third Party Materials, and your access to and use of such Third Party Materials are at your own risk.
|
41 |
+
10. Trademarks. You have not been granted any trademark license as part of this License and may not use any name or mark associated with Company without the prior written permission of Company, except to the extent necessary to make the reference required in the Attribution Notice as specified above or as is reasonably necessary in describing the FLUX.1 [dev] Model and its creators.
|
42 |
+
11. General. This License will be governed and construed under the laws of the State of Delaware without regard to conflicts of law provisions. If any provision or part of a provision of this License is unlawful, void or unenforceable, that provision or part of the provision is deemed severed from this License, and will not affect the validity and enforceability of any remaining provisions. The failure of Company to exercise or enforce any right or provision of this License will not operate as a waiver of such right or provision. This License does not confer any third-party beneficiary rights upon any other person or entity. This License, together with the Documentation, contains the entire understanding between you and Company regarding the subject matter of this License, and supersedes all other written or oral agreements and understandings between you and Company regarding such subject matter. No change or addition to any provision of this License will be binding unless it is in writing and signed by an authorized representative of both you and Company.
|
model_licenses/LICENSE-FLUX1-schnell
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
Apache License
|
4 |
+
Version 2.0, January 2004
|
5 |
+
http://www.apache.org/licenses/
|
6 |
+
|
7 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8 |
+
|
9 |
+
1. Definitions.
|
10 |
+
|
11 |
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
12 |
+
|
13 |
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
16 |
+
|
17 |
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
18 |
+
|
19 |
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
20 |
+
|
21 |
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
22 |
+
|
23 |
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
24 |
+
|
25 |
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
26 |
+
|
27 |
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
28 |
+
|
29 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
30 |
+
|
31 |
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
32 |
+
|
33 |
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
34 |
+
|
35 |
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
36 |
+
|
37 |
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
38 |
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
39 |
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
40 |
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
41 |
+
|
42 |
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
43 |
+
|
44 |
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
45 |
+
|
46 |
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
47 |
+
|
48 |
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
49 |
+
|
50 |
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
51 |
+
|
52 |
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
53 |
+
|
54 |
+
END OF TERMS AND CONDITIONS
|
pyproject.toml
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
name = "RF-Solver-Editing"
|
3 |
+
authors = [
|
4 |
+
{ name = "Jiangshan Wang, Junfu Pu, et al.", email = "wjs23@mails.tsinghua.edu.cn" },
|
5 |
+
]
|
6 |
+
description = "Inference codebase for RF-Solver-Editing"
|
7 |
+
readme = "README.md"
|
8 |
+
requires-python = ">=3.10"
|
9 |
+
license = { file = "LICENSE.md" }
|
10 |
+
dynamic = ["version"]
|
11 |
+
dependencies = [
|
12 |
+
"torch >= 2.0.0",
|
13 |
+
"torchvision",
|
14 |
+
"einops",
|
15 |
+
"fire >= 0.6.0",
|
16 |
+
"huggingface-hub",
|
17 |
+
"safetensors",
|
18 |
+
"sentencepiece",
|
19 |
+
"transformers",
|
20 |
+
"tokenizers",
|
21 |
+
"protobuf",
|
22 |
+
"requests",
|
23 |
+
"invisible-watermark",
|
24 |
+
]
|
25 |
+
|
26 |
+
[project.optional-dependencies]
|
27 |
+
streamlit = [
|
28 |
+
"streamlit",
|
29 |
+
"streamlit-keyup",
|
30 |
+
]
|
31 |
+
gradio = [
|
32 |
+
"gradio",
|
33 |
+
]
|
34 |
+
all = [
|
35 |
+
"flux[streamlit]",
|
36 |
+
"flux[gradio]",
|
37 |
+
]
|
38 |
+
|
39 |
+
[project.scripts]
|
40 |
+
flux = "flux.edit:main"
|
41 |
+
|
42 |
+
[build-system]
|
43 |
+
build-backend = "setuptools.build_meta"
|
44 |
+
requires = ["setuptools>=64", "wheel", "setuptools_scm>=8"]
|
45 |
+
|
46 |
+
[tool.ruff]
|
47 |
+
line-length = 110
|
48 |
+
target-version = "py310"
|
49 |
+
extend-exclude = ["/usr/lib/*"]
|
50 |
+
|
51 |
+
[tool.ruff.lint]
|
52 |
+
ignore = [
|
53 |
+
"E501", # line too long - will be fixed in format
|
54 |
+
]
|
55 |
+
|
56 |
+
[tool.ruff.format]
|
57 |
+
quote-style = "double"
|
58 |
+
indent-style = "space"
|
59 |
+
line-ending = "auto"
|
60 |
+
skip-magic-trailing-comma = false
|
61 |
+
docstring-code-format = true
|
62 |
+
exclude = [
|
63 |
+
"src/flux/_version.py", # generated by setuptools_scm
|
64 |
+
]
|
65 |
+
|
66 |
+
[tool.ruff.lint.isort]
|
67 |
+
combine-as-imports = true
|
68 |
+
force-wrap-aliases = true
|
69 |
+
known-local-folder = ["src"]
|
70 |
+
known-first-party = ["flux"]
|
71 |
+
|
72 |
+
[tool.pyright]
|
73 |
+
include = ["src"]
|
74 |
+
exclude = [
|
75 |
+
"**/__pycache__", # cache directories
|
76 |
+
"./typings", # generated type stubs
|
77 |
+
]
|
78 |
+
stubPath = "./typings"
|
79 |
+
|
80 |
+
[tool.tomlsort]
|
81 |
+
in_place = true
|
82 |
+
no_sort_tables = true
|
83 |
+
spaces_before_inline_comment = 1
|
84 |
+
spaces_indent_inline_array = 2
|
85 |
+
trailing_comma_inline_array = true
|
86 |
+
sort_first = [
|
87 |
+
"project",
|
88 |
+
"build-system",
|
89 |
+
"tool.setuptools",
|
90 |
+
]
|
91 |
+
|
92 |
+
# needs to be last for CI reasons
|
93 |
+
[tool.setuptools_scm]
|
94 |
+
write_to = "src/flux/_version.py"
|
95 |
+
parentdir_prefix_version = "flux-"
|
96 |
+
fallback_version = "0.0.0"
|
97 |
+
version_scheme = "post-release"
|
setup.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import setuptools
|
2 |
+
|
3 |
+
setuptools.setup()
|
src/edit.py
ADDED
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import re
|
3 |
+
import time
|
4 |
+
from dataclasses import dataclass
|
5 |
+
from glob import iglob
|
6 |
+
import argparse
|
7 |
+
import torch
|
8 |
+
from einops import rearrange
|
9 |
+
from fire import Fire
|
10 |
+
from PIL import ExifTags, Image
|
11 |
+
|
12 |
+
from flux.sampling import denoise, get_schedule, prepare, unpack
|
13 |
+
from flux.util import (configs, embed_watermark, load_ae, load_clip,
|
14 |
+
load_flow_model, load_t5)
|
15 |
+
from transformers import pipeline
|
16 |
+
from PIL import Image
|
17 |
+
import numpy as np
|
18 |
+
|
19 |
+
import os
|
20 |
+
|
21 |
+
NSFW_THRESHOLD = 0.85
|
22 |
+
|
23 |
+
@dataclass
|
24 |
+
class SamplingOptions:
|
25 |
+
source_prompt: str
|
26 |
+
target_prompt: str
|
27 |
+
# prompt: str
|
28 |
+
width: int
|
29 |
+
height: int
|
30 |
+
num_steps: int
|
31 |
+
guidance: float
|
32 |
+
seed: int | None
|
33 |
+
|
34 |
+
@torch.inference_mode()
|
35 |
+
def encode(init_image, torch_device, ae):
|
36 |
+
init_image = torch.from_numpy(init_image).permute(2, 0, 1).float() / 127.5 - 1
|
37 |
+
init_image = init_image.unsqueeze(0)
|
38 |
+
init_image = init_image.to(torch_device)
|
39 |
+
init_image = ae.encode(init_image.to()).to(torch.bfloat16)
|
40 |
+
return init_image
|
41 |
+
|
42 |
+
@torch.inference_mode()
|
43 |
+
def main(
|
44 |
+
args,
|
45 |
+
seed: int | None = None,
|
46 |
+
device: str = "cuda" if torch.cuda.is_available() else "cpu",
|
47 |
+
num_steps: int | None = None,
|
48 |
+
loop: bool = False,
|
49 |
+
offload: bool = False,
|
50 |
+
add_sampling_metadata: bool = True,
|
51 |
+
):
|
52 |
+
"""
|
53 |
+
Sample the flux model. Either interactively (set `--loop`) or run for a
|
54 |
+
single image.
|
55 |
+
|
56 |
+
Args:
|
57 |
+
name: Name of the model to load
|
58 |
+
height: height of the sample in pixels (should be a multiple of 16)
|
59 |
+
width: width of the sample in pixels (should be a multiple of 16)
|
60 |
+
seed: Set a seed for sampling
|
61 |
+
output_name: where to save the output image, `{idx}` will be replaced
|
62 |
+
by the index of the sample
|
63 |
+
prompt: Prompt used for sampling
|
64 |
+
device: Pytorch device
|
65 |
+
num_steps: number of sampling steps (default 4 for schnell, 50 for guidance distilled)
|
66 |
+
loop: start an interactive session and sample multiple times
|
67 |
+
guidance: guidance value used for guidance distillation
|
68 |
+
add_sampling_metadata: Add the prompt to the image Exif metadata
|
69 |
+
"""
|
70 |
+
torch.set_grad_enabled(False)
|
71 |
+
name = args.name
|
72 |
+
source_prompt = args.source_prompt
|
73 |
+
target_prompt = args.target_prompt
|
74 |
+
guidance = args.guidance
|
75 |
+
output_dir = args.output_dir
|
76 |
+
num_steps = args.num_steps
|
77 |
+
offload = args.offload
|
78 |
+
|
79 |
+
nsfw_classifier = pipeline("image-classification", model="Falconsai/nsfw_image_detection", device=device)
|
80 |
+
|
81 |
+
if name not in configs:
|
82 |
+
available = ", ".join(configs.keys())
|
83 |
+
raise ValueError(f"Got unknown model name: {name}, chose from {available}")
|
84 |
+
|
85 |
+
torch_device = torch.device(device)
|
86 |
+
if num_steps is None:
|
87 |
+
num_steps = 4 if name == "flux-schnell" else 25
|
88 |
+
|
89 |
+
# init all components
|
90 |
+
t5 = load_t5(torch_device, max_length=256 if name == "flux-schnell" else 512)
|
91 |
+
clip = load_clip(torch_device)
|
92 |
+
model = load_flow_model(name, device="cpu" if offload else torch_device)
|
93 |
+
ae = load_ae(name, device="cpu" if offload else torch_device)
|
94 |
+
|
95 |
+
if offload:
|
96 |
+
model.cpu()
|
97 |
+
torch.cuda.empty_cache()
|
98 |
+
ae.encoder.to(torch_device)
|
99 |
+
|
100 |
+
init_image = None
|
101 |
+
init_image = np.array(Image.open(args.source_img_dir).convert('RGB'))
|
102 |
+
|
103 |
+
shape = init_image.shape
|
104 |
+
|
105 |
+
new_h = shape[0] if shape[0] % 16 == 0 else shape[0] - shape[0] % 16
|
106 |
+
new_w = shape[1] if shape[1] % 16 == 0 else shape[1] - shape[1] % 16
|
107 |
+
|
108 |
+
init_image = init_image[:new_h, :new_w, :]
|
109 |
+
|
110 |
+
width, height = init_image.shape[0], init_image.shape[1]
|
111 |
+
init_image = encode(init_image, torch_device, ae)
|
112 |
+
|
113 |
+
rng = torch.Generator(device="cpu")
|
114 |
+
opts = SamplingOptions(
|
115 |
+
source_prompt=source_prompt,
|
116 |
+
target_prompt=target_prompt,
|
117 |
+
width=width,
|
118 |
+
height=height,
|
119 |
+
num_steps=num_steps,
|
120 |
+
guidance=guidance,
|
121 |
+
seed=seed,
|
122 |
+
)
|
123 |
+
|
124 |
+
if loop:
|
125 |
+
opts = parse_prompt(opts)
|
126 |
+
|
127 |
+
while opts is not None:
|
128 |
+
if opts.seed is None:
|
129 |
+
opts.seed = rng.seed()
|
130 |
+
print(f"Generating with seed {opts.seed}:\n{opts.source_prompt}")
|
131 |
+
t0 = time.perf_counter()
|
132 |
+
|
133 |
+
opts.seed = None
|
134 |
+
if offload:
|
135 |
+
ae = ae.cpu()
|
136 |
+
torch.cuda.empty_cache()
|
137 |
+
t5, clip = t5.to(torch_device), clip.to(torch_device)
|
138 |
+
|
139 |
+
info = {}
|
140 |
+
info['feature_path'] = args.feature_path
|
141 |
+
info['feature'] = {}
|
142 |
+
info['inject_step'] = args.inject
|
143 |
+
if not os.path.exists(args.feature_path):
|
144 |
+
os.mkdir(args.feature_path)
|
145 |
+
|
146 |
+
inp = prepare(t5, clip, init_image, prompt=opts.source_prompt)
|
147 |
+
inp_target = prepare(t5, clip, init_image, prompt=opts.target_prompt)
|
148 |
+
timesteps = get_schedule(opts.num_steps, inp["img"].shape[1], shift=(name != "flux-schnell"))
|
149 |
+
|
150 |
+
# offload TEs to CPU, load model to gpu
|
151 |
+
if offload:
|
152 |
+
t5, clip = t5.cpu(), clip.cpu()
|
153 |
+
torch.cuda.empty_cache()
|
154 |
+
model = model.to(torch_device)
|
155 |
+
|
156 |
+
# inversion initial noise
|
157 |
+
z, info = denoise(model, **inp, timesteps=timesteps, guidance=1, inverse=True, info=info)
|
158 |
+
|
159 |
+
inp_target["img"] = z
|
160 |
+
|
161 |
+
timesteps = get_schedule(opts.num_steps, inp_target["img"].shape[1], shift=(name != "flux-schnell"))
|
162 |
+
|
163 |
+
# denoise initial noise
|
164 |
+
x, _ = denoise(model, **inp_target, timesteps=timesteps, guidance=guidance, inverse=False, info=info)
|
165 |
+
|
166 |
+
if offload:
|
167 |
+
model.cpu()
|
168 |
+
torch.cuda.empty_cache()
|
169 |
+
ae.decoder.to(x.device)
|
170 |
+
|
171 |
+
# decode latents to pixel space
|
172 |
+
batch_x = unpack(x.float(), opts.width, opts.height)
|
173 |
+
|
174 |
+
for x in batch_x:
|
175 |
+
x = x.unsqueeze(0)
|
176 |
+
output_name = os.path.join(output_dir, "img_{idx}.jpg")
|
177 |
+
if not os.path.exists(output_dir):
|
178 |
+
os.makedirs(output_dir)
|
179 |
+
idx = 0
|
180 |
+
else:
|
181 |
+
fns = [fn for fn in iglob(output_name.format(idx="*")) if re.search(r"img_[0-9]+\.jpg$", fn)]
|
182 |
+
if len(fns) > 0:
|
183 |
+
idx = max(int(fn.split("_")[-1].split(".")[0]) for fn in fns) + 1
|
184 |
+
else:
|
185 |
+
idx = 0
|
186 |
+
|
187 |
+
with torch.autocast(device_type=torch_device.type, dtype=torch.bfloat16):
|
188 |
+
x = ae.decode(x)
|
189 |
+
|
190 |
+
if torch.cuda.is_available():
|
191 |
+
torch.cuda.synchronize()
|
192 |
+
t1 = time.perf_counter()
|
193 |
+
|
194 |
+
fn = output_name.format(idx=idx)
|
195 |
+
print(f"Done in {t1 - t0:.1f}s. Saving {fn}")
|
196 |
+
# bring into PIL format and save
|
197 |
+
x = x.clamp(-1, 1)
|
198 |
+
x = embed_watermark(x.float())
|
199 |
+
x = rearrange(x[0], "c h w -> h w c")
|
200 |
+
|
201 |
+
img = Image.fromarray((127.5 * (x + 1.0)).cpu().byte().numpy())
|
202 |
+
nsfw_score = [x["score"] for x in nsfw_classifier(img) if x["label"] == "nsfw"][0]
|
203 |
+
|
204 |
+
if nsfw_score < NSFW_THRESHOLD:
|
205 |
+
exif_data = Image.Exif()
|
206 |
+
exif_data[ExifTags.Base.Software] = "AI generated;txt2img;flux"
|
207 |
+
exif_data[ExifTags.Base.Make] = "Black Forest Labs"
|
208 |
+
exif_data[ExifTags.Base.Model] = name
|
209 |
+
if add_sampling_metadata:
|
210 |
+
exif_data[ExifTags.Base.ImageDescription] = source_prompt
|
211 |
+
img.save(fn, exif=exif_data, quality=95, subsampling=0)
|
212 |
+
idx += 1
|
213 |
+
else:
|
214 |
+
print("Your generated image may contain NSFW content.")
|
215 |
+
|
216 |
+
if loop:
|
217 |
+
print("-" * 80)
|
218 |
+
opts = parse_prompt(opts)
|
219 |
+
else:
|
220 |
+
opts = None
|
221 |
+
|
222 |
+
if __name__ == "__main__":
|
223 |
+
|
224 |
+
parser = argparse.ArgumentParser(description='RF-Edit')
|
225 |
+
|
226 |
+
parser.add_argument('--name', default='flux-dev', type=str,
|
227 |
+
help='flux model')
|
228 |
+
parser.add_argument('--source_img_dir', default='', type=str,
|
229 |
+
help='The path of the source image')
|
230 |
+
parser.add_argument('--source_prompt', type=str,
|
231 |
+
help='describe the content of the source image (or leaves it as null)')
|
232 |
+
parser.add_argument('--target_prompt', type=str,
|
233 |
+
help='describe the requirement of editing')
|
234 |
+
parser.add_argument('--feature_path', type=str, default='feature',
|
235 |
+
help='the path to save the feature ')
|
236 |
+
parser.add_argument('--guidance', type=float, default=5,
|
237 |
+
help='guidance scale')
|
238 |
+
parser.add_argument('--num_steps', type=int, default=25,
|
239 |
+
help='the number of timesteps for inversion and denoising')
|
240 |
+
parser.add_argument('--inject', type=int, default=20,
|
241 |
+
help='the number of timesteps which apply the feature sharing')
|
242 |
+
parser.add_argument('--output_dir', default='output', type=str,
|
243 |
+
help='the path of the edited image')
|
244 |
+
parser.add_argument('--offload', action='store_true', help='set it to True if the memory of GPU is not enough')
|
245 |
+
|
246 |
+
args = parser.parse_args()
|
247 |
+
|
248 |
+
main(args)
|
src/examples/edit/boy.jpg
ADDED
src/examples/edit/hiking.jpg
ADDED
src/examples/edit/horse.jpg
ADDED
src/examples/source/art.jpg
ADDED
Git LFS Details
|
src/examples/source/boy.jpg
ADDED
src/examples/source/cartoon.jpg
ADDED
src/examples/source/hiking.jpg
ADDED
src/examples/source/horse.jpg
ADDED
src/examples/source/nobel.jpg
ADDED
src/flux/__init__.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
try:
|
2 |
+
from ._version import version as __version__ # type: ignore
|
3 |
+
from ._version import version_tuple
|
4 |
+
except ImportError:
|
5 |
+
__version__ = "unknown (no version information available)"
|
6 |
+
version_tuple = (0, 0, "unknown", "noinfo")
|
7 |
+
|
8 |
+
from pathlib import Path
|
9 |
+
|
10 |
+
PACKAGE = __package__.replace("_", "-")
|
11 |
+
PACKAGE_ROOT = Path(__file__).parent
|
src/flux/__main__.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from .cli import app
|
2 |
+
|
3 |
+
if __name__ == "__main__":
|
4 |
+
app()
|
src/flux/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (503 Bytes). View file
|
|
src/flux/__pycache__/math.cpython-310.pyc
ADDED
Binary file (1.6 kB). View file
|
|
src/flux/__pycache__/math.cpython-38.pyc
ADDED
Binary file (1.46 kB). View file
|
|
src/flux/__pycache__/model.cpython-310.pyc
ADDED
Binary file (3.46 kB). View file
|
|
src/flux/__pycache__/sampling.cpython-310.pyc
ADDED
Binary file (3.68 kB). View file
|
|
src/flux/__pycache__/util.cpython-310.pyc
ADDED
Binary file (5.75 kB). View file
|
|