Diffusers
TalHach61 commited on
Commit
7b9eeac
·
verified ·
1 Parent(s): 175f7f4

Update README.md

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