Diffusers
TalHach61 commited on
Commit
34d8f6b
·
verified ·
1 Parent(s): d8c1bff

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +173 -5
README.md CHANGED
@@ -1,5 +1,173 @@
1
- ---
2
- license: other
3
- license_name: bria-legal-lobby
4
- license_link: https://bria.ai/legal-lobby
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: bria-legal-lobby
4
+ license_link: https://bria.ai/legal-lobby
5
+ ---
6
+
7
+
8
+ # BRIA-3.2 ControlNet Union Model Card
9
+
10
+ BRIA-3.2 ControlNet-Union, trained on the foundation of [BRIA-3.2 Text-to-Image](https://huggingface.co/briaai/BRIA-3.2), supports 6 control modes, including depth (0), canny (1), colorgrid (2), recolor (3), tile (4), pose (5). This model can be jointly used with other ControlNets.
11
+
12
+ Built with a strong commitment to legal compliance and responsible AI practices, this model ensures safe and scalable generative image capabilities for commercial use.
13
+
14
+
15
+ [CLICK HERE FOR A DEMO](https://huggingface.co/spaces/briaai/BRIA-3.2-ControlNet-Union)
16
+
17
+ For more information, please visit our [website](https://bria.ai/).
18
+
19
+ Join our [Discord community](https://discord.gg/Nxe9YW9zHS) for more information, tutorials, tools, and to connect with other users!
20
+
21
+ ### Get Access
22
+ BRIA-3.2-ControlNet-Union requires access to BRIA-3.2 Text-to-Image. For more information, [click here](https://huggingface.co/briaai/BRIA-3.2).
23
+
24
+ ### Model Description
25
+ - **Developed by:** BRIA AI
26
+ - **Model type:** Latent Flow-Matching Text-to-Image Model
27
+ - **License:** [Commercial licensing terms & conditions.](https://bria.ai/customer-general-terms-and-conditions)
28
+ - Purchase is required to license and access the model.
29
+ - **Model Description:** ControlNet Union for BRIA-3.2 Text-to-Image model. The model generates images guided by text and a conditioned image.
30
+ - **Resources for more information:** [BRIA AI](https://bria.ai/)
31
+
32
+
33
+ ## Control Mode
34
+ | Control Mode | Description |
35
+ |:------------:|:-----------:|
36
+ |0|depth
37
+ |1|canny
38
+ |2|colorgrid
39
+ |3|recolor
40
+ |4|tlie
41
+ |5|pose
42
+
43
+
44
+ ```python
45
+
46
+ ```
47
+
48
+ ### Installations
49
+ ```bash
50
+ pip install -qr https://huggingface.co/briaai/BRIA-3.2/resolve/main/requirements.txt
51
+ pip install diffusers==0.30.2, hf_hub_download
52
+ ```
53
+
54
+ ```python
55
+ from huggingface_hub import hf_hub_download
56
+ import os
57
+ try:
58
+ local_dir = os.path.dirname(__file__)
59
+ except:
60
+ local_dir = '.'
61
+
62
+ hf_hub_download(repo_id="briaai/BRIA-3.2", filename='pipeline_bria.py', local_dir=local_dir)
63
+ hf_hub_download(repo_id="briaai/BRIA-3.2", filename='transformer_bria.py', local_dir=local_dir)
64
+ hf_hub_download(repo_id="briaai/BRIA-3.2", filename='bria_utils.py', local_dir=local_dir)
65
+ hf_hub_download(repo_id="briaai/BRIA-3.2-ControlNet-Union", filename='pipeline_bria_controlnet.py', local_dir=local_dir)
66
+ hf_hub_download(repo_id="briaai/BRIA-3.2-ControlNet-Union", filename='controlnet_bria.py', local_dir=local_dir)
67
+ ```
68
+
69
+ # Inference
70
+ ```python
71
+ import torch
72
+ from diffusers.utils import load_image
73
+ from controlnet_bria import BriaControlNetModel
74
+ from pipeline_bria_controlnet import BriaControlNetPipeline
75
+ import PIL.Image as Image
76
+
77
+ RATIO_CONFIGS_1024 = {
78
+ 0.6666666666666666: {"width": 832, "height": 1248},
79
+ 0.7432432432432432: {"width": 880, "height": 1184},
80
+ 0.8028169014084507: {"width": 912, "height": 1136},
81
+ 1.0: {"width": 1024, "height": 1024},
82
+ 1.2456140350877194: {"width": 1136, "height": 912},
83
+ 1.3454545454545455: {"width": 1184, "height": 880},
84
+ 1.4339622641509433: {"width": 1216, "height": 848},
85
+ 1.5: {"width": 1248, "height": 832},
86
+ 1.5490196078431373: {"width": 1264, "height": 816},
87
+ 1.62: {"width": 1296, "height": 800},
88
+ 1.7708333333333333: {"width": 1360, "height": 768},
89
+ }
90
+
91
+ def resize_img(control_image):
92
+ image_ratio = control_image.width / control_image.height
93
+ ratio = min(RATIO_CONFIGS_1024.keys(), key=lambda k: abs(k - image_ratio))
94
+ to_height = RATIO_CONFIGS_1024[ratio]["height"]
95
+ to_width = RATIO_CONFIGS_1024[ratio]["width"]
96
+ resized_image = control_image.resize((to_width, to_height), resample=Image.Resampling.LANCZOS)
97
+ return resized_image
98
+
99
+
100
+ base_model = 'briaai/BRIA-3.2'
101
+ controlnet_model = 'briaai/BRIA-3.2-ControlNet-Union'
102
+ controlnet = BriaControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.bfloat16)
103
+ pipeline = BriaControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, trust_remote_code=True)
104
+ pipeline = pipeline.to(device="cuda", dtype=torch.bfloat16)
105
+
106
+ control_image_canny = load_image("https://huggingface.co/briaai/BRIA-3.2-ControlNet-Union/resolve/main/images/canny.jpg")
107
+ controlnet_conditioning_scale = 1.0
108
+ control_mode = 1
109
+ control_image_canny = resize_img(control_image_canny)
110
+ width, height = control_image_canny.size
111
+
112
+ prompt = 'In a serene living room, someone rests on a sapphire blue couch, diligently drawing in a rose-tinted notebook, with a sleek black coffee table, a muted green wall, an elegant geometric lamp, and a lush potted palm enhancing the peaceful ambiance.'
113
+
114
+ generator = torch.Generator(device="cuda").manual_seed(555)
115
+ image = pipeline(
116
+ prompt,
117
+ control_image=control_image_canny,
118
+ control_mode=control_mode,
119
+ width=width,
120
+ height=height,
121
+ controlnet_conditioning_scale=controlnet_conditioning_scale,
122
+ num_inference_steps=50,
123
+ max_sequence_length=128,
124
+ guidance_scale=5,
125
+ generator=generator,
126
+ negative_prompt="Ugly,Morbid,Extra fingers,Poorly drawn hands,Mutation,Blurry,Extra limbs,Gross proportions,Missing arms,Mutated hands,Long neck,Duplicate"
127
+ ).images[0]
128
+ print(image)
129
+ ```
130
+
131
+ # Multi-Controls Inference
132
+ ```python
133
+ import torch
134
+ from diffusers.utils import load_image
135
+ from controlnet_bria import BriaControlNetModel, BriaMultiControlNetModel
136
+ from pipeline_bria_controlnet import BriaControlNetPipeline
137
+ import PIL.Image as Image
138
+
139
+ base_model = 'briaai/BRIA-3.2'
140
+ controlnet_model = 'briaai/BRIA-3.2-ControlNet-Union'
141
+
142
+ controlnet = BriaControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.bfloat16)
143
+ controlnet = BriaMultiControlNetModel([controlnet])
144
+
145
+ pipe = BriaControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16, trust_remote_code=True)
146
+ pipe.to("cuda")
147
+
148
+ control_image_colorgrid = load_image("https://huggingface.co/briaai/BRIA-3.2-ControlNet-Union/resolve/main/images/colorgrid.jpg")
149
+ control_image_pose = load_image("https://huggingface.co/briaai/BRIA-3.2-ControlNet-Union/resolve/main/images/pose.jpg")
150
+
151
+ control_image = [control_image_colorgrid, control_image_pose]
152
+ controlnet_conditioning_scale = [0.5, 0.5]
153
+ control_mode = [2, 5]
154
+
155
+ width, height = control_image[0].size
156
+
157
+ prompt = 'Two kids in jackets play near a tent in a forest.'
158
+
159
+ generator = torch.Generator(device="cuda").manual_seed(555)
160
+ image = pipe(
161
+ prompt,
162
+ control_image=control_image,
163
+ control_mode=control_mode,
164
+ width=width,
165
+ height=height,
166
+ controlnet_conditioning_scale=controlnet_conditioning_scale,
167
+ num_inference_steps=50,
168
+ max_sequence_length=128,
169
+ guidance_scale=5,
170
+ generator=generator,
171
+ negative_prompt="Ugly,Morbid,Extra fingers,Poorly drawn hands,Mutation,Blurry,Extra limbs,Gross proportions,Missing arms,Mutated hands,Long neck,Duplicate"
172
+ ).images[0]
173
+ ```