jamesr66a commited on
Commit
c31e428
1 Parent(s): d82a4ec

Add data files & LICENSE

Browse files
Files changed (10) hide show
  1. .fluminaignore +167 -0
  2. .gitattributes +30 -0
  3. LICENSE +81 -0
  4. README.md +131 -5
  5. clone_weights.sh +1 -0
  6. example.png +3 -0
  7. fireworks.json +1 -0
  8. flumina.py +442 -0
  9. requirements.txt +6 -0
  10. t2i_output.png +3 -0
.fluminaignore ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .git/
2
+ .gitmodules
3
+ .gitattributes
4
+ data/.git/
5
+
6
+ # Byte-compiled / optimized / DLL files
7
+ __pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ .pybuilder/
81
+ target/
82
+
83
+ # Jupyter Notebook
84
+ .ipynb_checkpoints
85
+
86
+ # IPython
87
+ profile_default/
88
+ ipython_config.py
89
+
90
+ # pyenv
91
+ # For a library or package, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ # .python-version
94
+
95
+ # pipenv
96
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
98
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
99
+ # install all needed dependencies.
100
+ #Pipfile.lock
101
+
102
+ # poetry
103
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
105
+ # commonly ignored for libraries.
106
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107
+ #poetry.lock
108
+
109
+ # pdm
110
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
111
+ #pdm.lock
112
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
113
+ # in version control.
114
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
115
+ .pdm.toml
116
+ .pdm-python
117
+ .pdm-build/
118
+
119
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
120
+ __pypackages__/
121
+
122
+ # Celery stuff
123
+ celerybeat-schedule
124
+ celerybeat.pid
125
+
126
+ # SageMath parsed files
127
+ *.sage.py
128
+
129
+ # Environments
130
+ .env
131
+ .venv
132
+ env/
133
+ venv/
134
+ ENV/
135
+ env.bak/
136
+ venv.bak/
137
+
138
+ # Spyder project settings
139
+ .spyderproject
140
+ .spyproject
141
+
142
+ # Rope project settings
143
+ .ropeproject
144
+
145
+ # mkdocs documentation
146
+ /site
147
+
148
+ # mypy
149
+ .mypy_cache/
150
+ .dmypy.json
151
+ dmypy.json
152
+
153
+ # Pyre type checker
154
+ .pyre/
155
+
156
+ # pytype static type analyzer
157
+ .pytype/
158
+
159
+ # Cython debug symbols
160
+ cython_debug/
161
+
162
+ # PyCharm
163
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
164
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
165
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
166
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
167
+ #.idea/
.gitattributes CHANGED
@@ -33,3 +33,33 @@ 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
+ data/FLUX.1-dev-ControlNet-Union-Pro/diffusion_pytorch_model.safetensors filter=lfs diff=lfs merge=lfs -text
37
+ data/ae.safetensors filter=lfs diff=lfs merge=lfs -text
38
+ data/text_encoder/model.safetensors filter=lfs diff=lfs merge=lfs -text
39
+ data/text_encoder_2/model-00002-of-00002.safetensors filter=lfs diff=lfs merge=lfs -text
40
+ data/text_encoder_2/model-00001-of-00002.safetensors filter=lfs diff=lfs merge=lfs -text
41
+ data/tokenizer_2/spiece.model filter=lfs diff=lfs merge=lfs -text
42
+ data/transformer/diffusion_pytorch_model-00003-of-00003.safetensors filter=lfs diff=lfs merge=lfs -text
43
+ data/transformer/diffusion_pytorch_model-00002-of-00003.safetensors filter=lfs diff=lfs merge=lfs -text
44
+ data/transformer/diffusion_pytorch_model-00001-of-00003.safetensors filter=lfs diff=lfs merge=lfs -text
45
+ data/vae/diffusion_pytorch_model.safetensors filter=lfs diff=lfs merge=lfs -text
46
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/tile_result.jpg filter=lfs diff=lfs merge=lfs -text
47
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/tile.jpg filter=lfs diff=lfs merge=lfs -text
48
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/openpose_result.jpg filter=lfs diff=lfs merge=lfs -text
49
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/openpose.jpg filter=lfs diff=lfs merge=lfs -text
50
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/noise_result.jpg filter=lfs diff=lfs merge=lfs -text
51
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/noise.jpg filter=lfs diff=lfs merge=lfs -text
52
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/gray_result.jpg filter=lfs diff=lfs merge=lfs -text
53
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/gray.jpg filter=lfs diff=lfs merge=lfs -text
54
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/depth_result.jpg filter=lfs diff=lfs merge=lfs -text
55
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/depth.jpg filter=lfs diff=lfs merge=lfs -text
56
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/canny_result.jpg filter=lfs diff=lfs merge=lfs -text
57
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/canny.jpg filter=lfs diff=lfs merge=lfs -text
58
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/blur_result.jpg filter=lfs diff=lfs merge=lfs -text
59
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/blur.jpg filter=lfs diff=lfs merge=lfs -text
60
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/poster.png filter=lfs diff=lfs merge=lfs -text
61
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/teaser3.png filter=lfs diff=lfs merge=lfs -text
62
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/teaser2.png filter=lfs diff=lfs merge=lfs -text
63
+ data/FLUX.1-dev-ControlNet-Union-Pro/assets/teaser1.png filter=lfs diff=lfs merge=lfs -text
64
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
65
+ *.png filter=lfs diff=lfs merge=lfs -text
LICENSE CHANGED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ **FLUX.1 \[dev\] Non-Commercial License**
2
+
3
+ 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**”).
4
+
5
+ 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.
6
+
7
+ 1. **Definitions**. Capitalized terms used in this License but not defined herein have the following meanings:
8
+
9
+ 1. “**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.
10
+
11
+ 1. “**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.
12
+
13
+ 1. “**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.
14
+
15
+ 1. “**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.
16
+
17
+ 1. “**you**” or “**your**” means the individual or entity entering into this License with Company.
18
+
19
+ 1. **License Grant**.
20
+
21
+ 1. 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.
22
+
23
+ 1. 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.
24
+
25
+ 1. 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.
26
+
27
+ 1. 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.
28
+
29
+ 1. **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:
30
+
31
+ 1. 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;
32
+
33
+ 1. 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**”):
34
+
35
+ “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.
36
+
37
+ 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.”
38
+
39
+ 1. 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
40
+
41
+ 1. 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.
42
+
43
+ 1. 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.
44
+
45
+ 1. **Restrictions**. You will not, and will not permit, assist or cause any third party to
46
+
47
+ 1. 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;
48
+
49
+ 1. alter or remove copyright and other proprietary notices which appear on or in any portion of the FLUX.1 \[dev\] Model;
50
+
51
+ 1. 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
52
+
53
+ 1. offer or impose any terms on the FLUX.1 \[dev\] Model that alter, restrict, or are inconsistent with the terms of this License.
54
+
55
+ 1. 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;
56
+
57
+ 1. 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.
58
+
59
+ 1. **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.
60
+
61
+ 1. **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.
62
+
63
+ 1. **INDEMNIFICATION**
64
+
65
+ 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.
66
+
67
+ 1. **Termination; Survival**.
68
+
69
+ 1. This License will automatically terminate upon any breach by you of the terms of this License.
70
+
71
+ 1. We may terminate this License, in whole or in part, at any time upon notice (including electronic) to you.
72
+
73
+ 1. 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.
74
+
75
+ 1. 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.
76
+
77
+ 1. **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.
78
+
79
+ 1. **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.
80
+
81
+ 1. **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.
README.md CHANGED
@@ -1,5 +1,131 @@
1
- ---
2
- license: other
3
- license_name: flux-1-dev-non-commercial-license
4
- license_link: LICENSE
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: flux-1-dev-non-commercial-license
4
+ license_link: LICENSE
5
+ ---
6
+
7
+ # FLUX.1 [dev] -- Flumina Server App
8
+
9
+ This repository contains an implementation of FLUX.1 [dev] inference on Fireworks AI's new Flumina Server App toolkit.
10
+
11
+ ![Example output](example.png)
12
+
13
+ ## Deploying FLUX.1 [dev] to Fireworks On-Demand
14
+
15
+ FLUX.1 [dev] (bfloat16) is available on Fireworks via [on-demand deployments](https://docs.fireworks.ai/guides/ondemand-deployments). It can be deployed in a few simple steps:
16
+
17
+ ### Prerequisite: Clone the Weights into this Repository
18
+
19
+ 1. Authenticate with HuggingFace with `huggingface-cli login`
20
+ 2. Go to the model [repository](https://huggingface.co/black-forest-labs/FLUX.1-dev) and accept the license agreement
21
+ 3. From the root of this repository, clone the model into the `data/` folder by running `clone_weights.sh`
22
+
23
+ ### Prerequisite: Install the Flumina CLI
24
+
25
+ The Flumina CLI is included with the [fireworks-ai](https://pypi.org/project/fireworks-ai/) Python package. It can be installed with pip like so:
26
+ ```bash
27
+ pip install 'fireworks-ai[flumina]>=0.15.7'
28
+ ```
29
+
30
+ Also get an API key from the [Fireworks site](https://fireworks.ai/account/api-keys) and set it in the Flumina CLI:
31
+
32
+ ```bash
33
+ flumina set-api-key YOURAPIKEYHERE
34
+ ```
35
+
36
+ ### Creating an On-Demand Deployment
37
+
38
+ `flumina deploy` can be used to create an on-demand deployment. When invoked with a model name that exists already, it will create a new deployment in your account which has that model:
39
+
40
+ ```bash
41
+ flumina deploy accounts/fireworks/models/flux-1-dev
42
+ ```
43
+
44
+ When successful, the CLI will print out example commands to call your new deployment, for example:
45
+
46
+ ```bash
47
+ curl -X POST 'https://api.fireworks.ai/inference/v1/workflows/accounts/fireworks/models/flux-1-dev/control_net?deployment=accounts/u-6jamesr6-63834f/deployments/2a7d8da9' \
48
+ -H 'Authorization: Bearer API_KEY' \
49
+ -F "prompt=<value>" \
50
+ -F "control_image=<value>" \
51
+ -F "control_mode=<value>" \
52
+ -F "aspect_ratio=16:9" \
53
+ -F "guidance_scale=3.5" \
54
+ -F "num_inference_steps=30" \
55
+ -F "seed=0" \
56
+ -F "controlnet_conditioning_scale=<value>"
57
+
58
+ curl -X POST 'https://api.fireworks.ai/inference/v1/workflows/accounts/fireworks/models/flux-1-dev/text_to_image?deployment=accounts/u-6jamesr6-63834f/deployments/2a7d8da9' \
59
+ -H 'Authorization: Bearer API_KEY' \
60
+ -H "Content-Type: application/json" \
61
+ -d '{
62
+ "prompt": "<value>",
63
+ "aspect_ratio": "16:9",
64
+ "guidance_scale": 3.5,
65
+ "num_inference_steps": 30,
66
+ "seed": 0
67
+ }'
68
+ ```
69
+
70
+ Your deployment can also be administered using the Flumina CLI. Useful commands include:
71
+ * `flumina list deployments` to show all of your deployments
72
+ * `flumina get deployment` to get details about a specific deployment
73
+ * `flumina delete deployment` to delete a deployment
74
+
75
+ ## Add-ons
76
+
77
+ Add-ons are packages you can upload to Fireworks and load into your deployed model. This Flumina app implements two types of add-ons: "controlnet_union" and "lora".
78
+
79
+ ### Deploying an existing add-on to your FLUX on-demand deployment
80
+
81
+ Existing addons can be deployed to Fireworks via the `flumina create deployed_addon` command. The command takes two arguments:
82
+ * The resource name of the addon to be deployed
83
+ * The resource name of the deployment on which to deploy the add-on
84
+
85
+ Both resource names can either be an ID (e.g. `my-addon` or `012345` for addons and deployments respectively) in which case it is assumed that the resource is in your Fireworks account or they can be fully-qualified names like `accounts/my-account/models/my-addon` or `accounts/my-account/deployments/my-deployment`.
86
+
87
+ For example:
88
+
89
+ ```bash
90
+ flumina create deployed_addon accounts/fireworks/models/flux-1-dev-controlnet-union 0123456
91
+ ```
92
+
93
+ This will deploy the `flux-1-dev-controlnet-union` add-on in the fireworks account to your deployment named `0123456`.
94
+
95
+
96
+ ### Creating custom addons (ControlNet and LoRA adapters)
97
+
98
+ This model supports addons (specifically ControlNet Union and LoRA adapters) in the HuggingFace diffusers format. Here is an example of taking an existing LoRA addon from HuggingFace and deploying it to Fireworks:
99
+
100
+ ```bash
101
+ git clone https://huggingface.co/brushpenbob/flux-midjourney-anime
102
+ cd flux-midjourney-anime
103
+ flumina init addon lora --allow-non-empty
104
+ flumina create model flux-1-dev-midjourney-anime --base-model accounts/fireworks/models/flux-1-dev
105
+ ```
106
+
107
+ Then you can deploy it to your on-demand deployment like so:
108
+
109
+ ```bash
110
+ flumina create deployed_addon flux-1-dev-midjourney-anime 0123456
111
+ ```
112
+
113
+ ## What is Flumina?
114
+
115
+ Flumina is Fireworks.ai’s new system for hosting Server Apps that allows users to deploy deep learning inference to production in minutes, not weeks.
116
+
117
+ ## What does Flumina offer for FLUX models?
118
+
119
+ Flumina offers the following benefits:
120
+
121
+ * Clear, precise definition of the server-side workload by looking at the server app implementation (you are here)
122
+ * Extensibility interface, which allows for dynamic loading/dispatching of add-ons server-side. For FLUX:
123
+ * ControlNet (Union) adapters
124
+ * LoRA adapters
125
+ * Off-the-shelf support for standing up on-demand capacity for the Server App on Fireworks
126
+ * Further, customization of the logic of the deployment by modifying the Server App and deploying the modified version.
127
+
128
+ ## Deploying Custom FLUX.1 [dev] Apps to Fireworks On-demand
129
+
130
+ Flumina base app upload is coming soon!
131
+
clone_weights.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ git clone https://huggingface.co/black-forest-labs/FLUX.1-dev data
example.png ADDED

Git LFS Details

  • SHA256: 4400ebd7b6515bfcbc9f0e6893aba544d7123a2e155d4a913ba2af4b6d899e5d
  • Pointer size: 132 Bytes
  • Size of remote file: 3.9 MB
fireworks.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"_is_flumina_model": true}
flumina.py ADDED
@@ -0,0 +1,442 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import io
3
+ from fireworks.flumina import FluminaModule, main as flumina_main
4
+ from fireworks.flumina.route import post
5
+ import pydantic
6
+ from pydantic import BaseModel
7
+ from fastapi import File, Form, Header, UploadFile, HTTPException
8
+ from fastapi.responses import Response
9
+ import math
10
+ import os
11
+ import re
12
+ import PIL.Image as Image
13
+ from typing import Dict, Optional, Set, Tuple
14
+
15
+ from diffusers import FluxPipeline, FluxControlNetPipeline, FluxControlNetModel
16
+ from diffusers.models import FluxMultiControlNetModel
17
+
18
+
19
+ # Util
20
+ def _aspect_ratio_to_width_height(aspect_ratio: str) -> Tuple[int, int]:
21
+ """
22
+ Convert specified aspect ratio to a height/width pair.
23
+ """
24
+ if ":" not in aspect_ratio:
25
+ raise ValueError(
26
+ f"Invalid aspect ratio: {aspect_ratio}. Aspect ratio must be in w:h format, e.g. 16:9"
27
+ )
28
+
29
+ w, h = aspect_ratio.split(":")
30
+ try:
31
+ w, h = int(w), int(h)
32
+ except ValueError:
33
+ raise ValueError(
34
+ f"Invalid aspect ratio: {aspect_ratio}. Aspect ratio must be in w:h format, e.g. 16:9"
35
+ )
36
+
37
+ valid_aspect_ratios = [
38
+ (1, 1),
39
+ (21, 9),
40
+ (16, 9),
41
+ (3, 2),
42
+ (5, 4),
43
+ (4, 5),
44
+ (2, 3),
45
+ (9, 16),
46
+ (9, 21),
47
+ ]
48
+ if (w, h) not in valid_aspect_ratios:
49
+ raise ValueError(
50
+ f"Invalid aspect ratio: {aspect_ratio}. Aspect ratio must be one of {valid_aspect_ratios}"
51
+ )
52
+
53
+ # We consider megapixel not 10^6 pixels but 2^20 (1024x1024) pixels
54
+ TARGET_SIZE_MP = 1
55
+ target_size = TARGET_SIZE_MP * 2**20
56
+
57
+ width = math.sqrt(target_size / (w * h)) * w
58
+ height = math.sqrt(target_size / (w * h)) * h
59
+
60
+ PAD_MULTIPLE = 64
61
+
62
+ if PAD_MULTIPLE:
63
+ width = width // PAD_MULTIPLE * PAD_MULTIPLE
64
+ height = height // PAD_MULTIPLE * PAD_MULTIPLE
65
+
66
+ return int(width), int(height)
67
+
68
+
69
+ def encode_image(
70
+ image: Image.Image, mime_type: str, jpeg_quality: int = 95
71
+ ) -> bytes:
72
+ buffered = io.BytesIO()
73
+ if mime_type == "image/jpeg":
74
+ if jpeg_quality < 0 or jpeg_quality > 100:
75
+ raise ValueError(
76
+ f"jpeg_quality must be between 0 and 100, not {jpeg_quality}"
77
+ )
78
+ image.save(buffered, format="JPEG", quality=jpeg_quality)
79
+ elif mime_type == "image/png":
80
+ image.save(buffered, format="PNG")
81
+ else:
82
+ raise ValueError(f"invalid mime_type {mime_type}")
83
+ return buffered.getvalue()
84
+
85
+
86
+ def parse_accept_header(accept: str) -> str:
87
+ # Split the string into the comma-separated components
88
+ parts = accept.split(",")
89
+ weighted_types = []
90
+
91
+ for part in parts:
92
+ # Use a regular expression to extract the media type and the optional q-factor
93
+ match = re.match(
94
+ r"(?P<media_type>[^;]+)(;q=(?P<q_factor>\d+(\.\d+)?))?", part.strip()
95
+ )
96
+ if match:
97
+ media_type = match.group("media_type").strip()
98
+ q_factor = (
99
+ float(match.group("q_factor")) if match.group("q_factor") else 1.0
100
+ )
101
+ weighted_types.append((media_type, q_factor))
102
+ else:
103
+ raise ValueError(f"Malformed Accept header value: {part.strip()}")
104
+
105
+ # Sort the media types by q-factor, descending
106
+ sorted_types = sorted(weighted_types, key=lambda x: x[1], reverse=True)
107
+
108
+ # Define a list of supported MIME types
109
+ supported_types = ["image/jpeg", "image/png"]
110
+
111
+ for media_type, _ in sorted_types:
112
+ if media_type in supported_types:
113
+ return media_type
114
+ elif media_type == "*/*":
115
+ return supported_types[0] # Default to the first supported type
116
+ elif media_type == "image/*":
117
+ # If "image/*" is specified, return the first matching supported image type
118
+ return supported_types[0]
119
+
120
+ raise ValueError(f"Accept header did not include any supported MIME types: {supported_types}")
121
+
122
+
123
+ # Define your request and response schemata here
124
+ class Text2ImageRequest(BaseModel):
125
+ prompt: str
126
+ aspect_ratio: str = "16:9"
127
+ guidance_scale: float = 3.5
128
+ num_inference_steps: int = 30
129
+ seed: int = 0
130
+
131
+
132
+ class Error(BaseModel):
133
+ object: str = "error"
134
+ type: str = "invalid_request_error"
135
+ message: str
136
+
137
+
138
+ class ErrorResponse(BaseModel):
139
+ error: Error = pydantic.Field(default_factory=Error)
140
+
141
+
142
+ class BillingInfo(BaseModel):
143
+ steps: int
144
+ height: int
145
+ width: int
146
+ is_control_net: bool
147
+
148
+
149
+ class FluminaModule(FluminaModule):
150
+ def __init__(self):
151
+ super().__init__()
152
+ self.hf_model = FluxPipeline.from_pretrained('./data', torch_dtype=torch.bfloat16)
153
+ self.hf_model.to(device='cuda', dtype=torch.bfloat16)
154
+
155
+ # Map from resource qualname to pipeline
156
+ self.cnet_union_pipes: Dict[str, FluxControlNetPipeline] = {}
157
+ # Optional resource qualname to specify which Controlnet Union pipeline
158
+ # is active
159
+ self.active_cnet_union: Optional[str] = None
160
+
161
+ self.lora_adapters: Set[str] = set()
162
+ self.active_lora_adapter: Optional[str] = None
163
+
164
+ self._test_return_sync_response = False
165
+
166
+ def _error_response(self, code: int, message: str) -> Response:
167
+ response_json = ErrorResponse(
168
+ error=Error(message=message),
169
+ ).json()
170
+ if self._test_return_sync_response:
171
+ return response_json
172
+ else:
173
+ return Response(
174
+ response_json,
175
+ status_code=code,
176
+ media_type="application/json",
177
+ )
178
+
179
+ def _image_response(self, img: Image.Image, mime_type: str, billing_info: BillingInfo):
180
+ image_bytes = encode_image(img, mime_type)
181
+ if self._test_return_sync_response:
182
+ return image_bytes
183
+ else:
184
+ headers = {'Fireworks-Billing-Properties': billing_info.json()}
185
+ return Response(image_bytes, status_code=200, media_type=mime_type, headers=headers)
186
+
187
+ @post('/text_to_image')
188
+ async def text_to_image(
189
+ self,
190
+ body: Text2ImageRequest,
191
+ accept: str = Header("image/jpeg"),
192
+ ):
193
+ mime_type = parse_accept_header(accept)
194
+ width, height = _aspect_ratio_to_width_height(body.aspect_ratio)
195
+ img = self.hf_model(
196
+ prompt=body.prompt,
197
+ height=height,
198
+ width=width,
199
+ guidance_scale=body.guidance_scale,
200
+ num_inference_steps=body.num_inference_steps,
201
+ generator=torch.Generator('cuda').manual_seed(body.seed),
202
+ )
203
+ assert len(img.images) == 1, len(img.images)
204
+
205
+ billing_info = BillingInfo(
206
+ steps=body.num_inference_steps,
207
+ height=height,
208
+ width=width,
209
+ is_control_net=False,
210
+ )
211
+ return self._image_response(img.images[0], mime_type, billing_info)
212
+
213
+ @post('/control_net')
214
+ async def control_net(
215
+ self,
216
+ prompt: str = Form(...),
217
+ control_image: UploadFile = File(...),
218
+ control_mode: int = Form(...),
219
+ aspect_ratio: str = Form("16:9"),
220
+ guidance_scale: float = Form(3.5),
221
+ num_inference_steps: int = Form(30),
222
+ seed: int = Form(0),
223
+ # ControlNet Parameters
224
+ controlnet_conditioning_scale: Optional[float] = Form(1.0),
225
+ accept: str = Header("image/jpeg"),
226
+ ):
227
+ mime_type = parse_accept_header(accept)
228
+ if self.active_cnet_union is None:
229
+ return self._error_response(400, f"Must call `/control_net` endpoint with a ControlNet model specified in the URI")
230
+
231
+ if control_mode is None:
232
+ return self._error_response(400, f"control_mode must be specified when calling a ControlNet model")
233
+
234
+ # Read and convert the control image to a PIL Image object
235
+ try:
236
+ image_data = await control_image.read()
237
+ pil_image = Image.open(io.BytesIO(image_data))
238
+ except Exception as e:
239
+ return self._error_response(400, f"Invalid image format: {e}")
240
+
241
+ width, height = _aspect_ratio_to_width_height(aspect_ratio)
242
+ img = self.cnet_union_pipes[self.active_cnet_union](
243
+ prompt=prompt,
244
+ control_image=[pil_image],
245
+ control_mode=[control_mode],
246
+ height=height,
247
+ width=width,
248
+ num_inference_steps=num_inference_steps,
249
+ guidance_scale=guidance_scale,
250
+ controlnet_conditioning_scale=[controlnet_conditioning_scale],
251
+ generator=torch.Generator('cuda').manual_seed(seed),
252
+ )
253
+ assert len(img.images) == 1, len(img.images)
254
+
255
+ billing_info = BillingInfo(
256
+ steps=num_inference_steps,
257
+ height=height,
258
+ width=width,
259
+ is_control_net=True,
260
+ )
261
+ return self._image_response(img.images[0], mime_type, billing_info)
262
+
263
+
264
+ @property
265
+ def supported_addon_types(self):
266
+ return ['controlnet_union', 'lora']
267
+
268
+ # Addon interface
269
+ def load_addon(
270
+ self, addon_account_id: str, addon_model_id: str, addon_type: str, addon_data_path: os.PathLike
271
+ ):
272
+ if addon_type not in self.supported_addon_types:
273
+ raise ValueError(f"Invalid addon type {addon_type}. Supported types: {self.supported_addon_types}")
274
+
275
+ qualname = f"accounts/{addon_account_id}/models/{addon_model_id}"
276
+
277
+ if addon_type == 'controlnet_union':
278
+ cnet_model = FluxControlNetModel.from_pretrained(addon_data_path)
279
+ multi_cnet_model = FluxMultiControlNetModel([cnet_model])
280
+ multi_cnet_model.to(device='cuda', dtype=torch.bfloat16)
281
+ self.cnet_union_pipes[qualname] = FluxControlNetPipeline(
282
+ scheduler=self.hf_model.scheduler,
283
+ vae=self.hf_model.vae,
284
+ text_encoder=self.hf_model.text_encoder,
285
+ tokenizer=self.hf_model.tokenizer,
286
+ text_encoder_2=self.hf_model.text_encoder_2,
287
+ tokenizer_2=self.hf_model.tokenizer_2,
288
+ transformer=self.hf_model.transformer,
289
+ controlnet=multi_cnet_model,
290
+ )
291
+ elif addon_type == 'lora':
292
+ self.hf_model.load_lora_weights(addon_data_path, adapter_name=qualname)
293
+ self.lora_adapters.add(qualname)
294
+ else:
295
+ raise NotImplementedError(f'Addon support for type {addon_type} not implemented')
296
+
297
+ def unload_addon(
298
+ self, addon_account_id: str, addon_model_id: str, addon_type: str
299
+ ):
300
+ qualname = f"accounts/{addon_account_id}/models/{addon_model_id}"
301
+
302
+ if addon_type == 'controlnet_union':
303
+ assert qualname in self.cnet_union_pipes
304
+ self.cnet_union_pipes.pop(qualname)
305
+ elif addon_type == 'lora':
306
+ assert qualname in self.lora_adapters
307
+ self.hf_model.delete_adapters([qualname])
308
+ self.lora_adapters.remove(qualname)
309
+ else:
310
+ raise NotImplementedError(f'Addon support for type {addon_type} not implemented')
311
+
312
+ def activate_addon(self, addon_account_id: str, addon_model_id: str):
313
+ qualname = f"accounts/{addon_account_id}/models/{addon_model_id}"
314
+
315
+ if qualname in self.cnet_union_pipes:
316
+ if self.active_cnet_union is not None:
317
+ raise ValueError(f"ControlNet Union {self.active_cnet_union} already active. Multi-controlnet union not supported!")
318
+
319
+ self.active_cnet_union = qualname
320
+ return
321
+
322
+ if qualname in self.lora_adapters:
323
+ if self.active_lora_adapter is not None:
324
+ raise ValueError(f"LoRA adapter {self.active_lora_adapter} already active. Multi-LoRA not yet supported")
325
+
326
+ self.active_lora_adapter = qualname
327
+ return
328
+
329
+ raise ValueError(f"Unknown addon {qualname}")
330
+
331
+
332
+ def deactivate_addon(self, addon_account_id: str, addon_model_id: str):
333
+ qualname = f"accounts/{addon_account_id}/models/{addon_model_id}"
334
+
335
+ if self.active_cnet_union == qualname:
336
+ self.active_cnet_union = None
337
+ elif self.active_lora_adapter == qualname:
338
+ self.active_lora_adapter = None
339
+ else:
340
+ raise AssertionError(f'Addon {qualname} not loaded!')
341
+
342
+
343
+ if __name__ == "__flumina_main__":
344
+ f = FluminaModule()
345
+ flumina_main(f)
346
+
347
+ if __name__ == "__main__":
348
+ f = FluminaModule()
349
+ f._test_return_sync_response = True
350
+
351
+ import asyncio
352
+
353
+ # Test text-to-image
354
+ t2i_out = asyncio.run(f.text_to_image(
355
+ Text2ImageRequest(
356
+ prompt="A quick brown fox",
357
+ aspect_ratio="16:9",
358
+ guidance_scale=3.5,
359
+ num_inference_steps=30,
360
+ seed=0,
361
+ ),
362
+ accept="image/jpeg",
363
+ ))
364
+ assert isinstance(t2i_out, bytes), t2i_out
365
+ with open('output.png', 'wb') as out_file:
366
+ out_file.write(t2i_out)
367
+
368
+ # Test ControlNet
369
+ cn_adapter_path = os.environ.get('CONTROLNET_ADAPTER_PATH', None)
370
+ if cn_adapter_path is not None:
371
+ addon_acct_id, addon_model_id = "fireworks", "test_controlnet"
372
+ f.load_addon(addon_acct_id, addon_model_id, "controlnet_union", cn_adapter_path)
373
+ f.activate_addon(addon_acct_id, addon_model_id)
374
+
375
+ import cv2
376
+ class FakeFile:
377
+ def __init__(self, filename):
378
+ self.filename = filename
379
+
380
+ async def read(self):
381
+ image = cv2.imread(self.filename)
382
+
383
+ # Check if the image is loaded correctly
384
+ if image is None:
385
+ raise ValueError("Image not found or unable to open.")
386
+
387
+ # Apply GaussianBlur to reduce noise and avoid false edge detection
388
+ blurred_image = cv2.GaussianBlur(image, (5, 5), 1.4)
389
+
390
+ # Perform Canny edge detection
391
+ edges = cv2.Canny(blurred_image, threshold1=0, threshold2=50)
392
+ control_image = Image.fromarray(edges).convert("RGB")
393
+ bio = io.BytesIO()
394
+ control_image.save(bio, format="PNG")
395
+ bio.seek(0)
396
+ return bio.getvalue()
397
+
398
+ cn_out = asyncio.run(f.control_net(
399
+ prompt="Cyberpunk future fox nighttime purple and green",
400
+ control_image=FakeFile('output.png'),
401
+ control_mode=0, # canny
402
+ aspect_ratio="16:9",
403
+ guidance_scale=3.5,
404
+ num_inference_steps=30,
405
+ seed=0,
406
+ controlnet_conditioning_scale=1.0,
407
+ accept="image/png",
408
+ ))
409
+ assert isinstance(cn_out, bytes), cn_out
410
+ f.deactivate_addon(addon_acct_id, addon_model_id)
411
+ f.unload_addon(addon_acct_id, addon_model_id, "controlnet_union")
412
+
413
+ with open('output_cn.png', 'wb') as cn_out_file:
414
+ cn_out_file.write(cn_out)
415
+ else:
416
+ print('Skipping ControlNet test. Set CONTROLNET_ADAPTER_PATH to enable it.')
417
+
418
+ lora_adapter_path = os.environ.get('LORA_ADAPTER_PATH', None)
419
+ if lora_adapter_path is not None:
420
+ addon_acct_id, addon_model_id = "fireworks", "test_lora"
421
+ f.load_addon(addon_acct_id, addon_model_id, "lora", lora_adapter_path)
422
+ f.activate_addon(addon_acct_id, addon_model_id)
423
+
424
+ lora_out = asyncio.run(f.text_to_image(
425
+ Text2ImageRequest(
426
+ prompt="A quick brown fox",
427
+ aspect_ratio="16:9",
428
+ guidance_scale=3.5,
429
+ num_inference_steps=30,
430
+ seed=0,
431
+ ),
432
+ accept="image/jpeg;image/png",
433
+ ))
434
+ assert isinstance(lora_out, bytes), lora_out
435
+
436
+ f.deactivate_addon(addon_acct_id, addon_model_id)
437
+ f.unload_addon(addon_acct_id, addon_model_id, "lora")
438
+
439
+ with open('output_lora.png', 'wb') as lora_out_file:
440
+ lora_out_file.write(lora_out)
441
+ else:
442
+ print('Skipping ControlNet test. Set LORA_ADAPTER_PATH to enable it.')
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ git+https://github.com/huggingface/diffusers.git@c4a8979
2
+ numpy<2
3
+ tokenizers<0.19
4
+ transformers>=4
5
+ flash-attn==2.6.3
6
+ fsspec>=2023.1.0
t2i_output.png ADDED

Git LFS Details

  • SHA256: 685033698f71fde69ca84605b965ed3fae79fd8b4e4700f18224e4cfab977f58
  • Pointer size: 132 Bytes
  • Size of remote file: 1.56 MB