EndlessSora commited on
Commit
5729c92
·
1 Parent(s): 0c3c7ef

replace examples & add safety watermark

Browse files
app.py CHANGED
@@ -22,6 +22,7 @@ import torch
22
  import gc
23
  from huggingface_hub import snapshot_download
24
  from pillow_heif import register_heif_opener
 
25
 
26
  from pipelines.pipeline_infu_flux import InfUFluxPipeline
27
 
@@ -137,6 +138,30 @@ def prepare_pipeline(model_version, enable_realism, enable_anti_blur):
137
  return pipeline
138
 
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  @spaces.GPU(duration=120)
141
  def generate_image(
142
  input_image,
@@ -173,6 +198,7 @@ def generate_image(
173
  infusenet_guidance_start=infusenet_guidance_start,
174
  infusenet_guidance_end=infusenet_guidance_end,
175
  )
 
176
  except Exception as e:
177
  print(e)
178
  gr.Error(f"An error occurred: {e}")
@@ -186,13 +212,13 @@ def generate_examples(id_image, control_image, prompt_text, seed, enable_realism
186
 
187
 
188
  sample_list = [
189
- ['./assets/examples/yann-lecun_resize.jpg', None, 'A sophisticated gentleman exuding confidence. He is dressed in a 1990s brown plaid jacket with a high collar, paired with a dark grey turtleneck. His trousers are tailored and charcoal in color, complemented by a sleek leather belt. The background showcases an elegant library with bookshelves, a marble fireplace, and warm lighting, creating a refined and cozy atmosphere. His relaxed posture and casual hand-in-pocket stance add to his composed and stylish demeanor', 666, False, False, 'aes_stage2'],
190
- ['./assets/examples/yann-lecun_resize.jpg', './assets/examples/man_pose.jpg', 'A man, portrait, cinematic', 42, True, False, 'aes_stage2'],
191
- ['./assets/examples/yann-lecun_resize.jpg', './assets/examples/yann-lecun_resize.jpg', 'A man, portrait, cinematic', 12345, False, False, 'sim_stage1'],
192
- ['./assets/examples/yangmi.jpg', None, 'A woman, portrait, cinematic', 1621695706, False, False, 'sim_stage1'],
193
- ['./assets/examples/yangmi.jpg', None, 'A young woman holding a sign with the text "InfiniteYou", "Infinite" in black and "You" in red, pure background', 3724009366, False, False, 'aes_stage2'],
194
- ['./assets/examples/yangmi.jpg', None, 'A photo of an elegant Javanese bride in traditional attire, with long hair styled into intricate a braid made of many fresh flowers, wearing a delicate headdress made from sequins and beads. She\'s holding flowers, light smiling at the camera, against a backdrop adorned with orchid blooms. The scene captures her grace as she stands amidst soft pastel colors, adding to its dreamy atmosphere', 42, True, False, 'aes_stage2'],
195
- ['./assets/examples/yangmi.jpg', None, 'A photo of an elegant Javanese bride in traditional attire, with long hair styled into intricate a braid made of many fresh flowers, wearing a delicate headdress made from sequins and beads. She\'s holding flowers, light smiling at the camera, against a backdrop adorned with orchid blooms. The scene captures her grace as she stands amidst soft pastel colors, adding to its dreamy atmosphere', 42, False, False, 'sim_stage1'],
196
  ]
197
 
198
  with gr.Blocks() as demo:
@@ -304,7 +330,7 @@ with gr.Blocks() as demo:
304
  """
305
  ---
306
  ### 📜 Disclaimer and Licenses
307
- Some images in this demo are from public domains or generated by models. These pictures are intended solely to show the capabilities of our research. If you have any concerns, please contact us, and we will promptly remove any inappropriate content.
308
 
309
  The use of the released code, model, and demo must strictly adhere to the respective licenses.
310
  Our code is released under the [Apache 2.0 License](https://github.com/bytedance/InfiniteYou/blob/main/LICENSE),
@@ -312,7 +338,7 @@ with gr.Blocks() as demo:
312
  for academic research purposes only. Any manual or automatic downloading of the face models from [InsightFace](https://github.com/deepinsight/insightface),
313
  the [FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev) base model, LoRAs, *etc.*, must follow their original licenses and be used only for academic research purposes.
314
 
315
- This research aims to positively impact the Generative AI field. Users are granted freedom to create images using this tool, but they must comply with local laws and use it responsibly. The developers do not assume any responsibility for potential misuse.
316
  """
317
  )
318
 
 
22
  import gc
23
  from huggingface_hub import snapshot_download
24
  from pillow_heif import register_heif_opener
25
+ from PIL import Image, ImageDraw, ImageFont
26
 
27
  from pipelines.pipeline_infu_flux import InfUFluxPipeline
28
 
 
138
  return pipeline
139
 
140
 
141
+ def add_safety_watermark(image, text='AI Generated', font_path=None):
142
+ width, height = image.size
143
+ draw = ImageDraw.Draw(image)
144
+
145
+ font_size = int(height * 0.028)
146
+ if font_path:
147
+ font = ImageFont.truetype(font_path, font_size)
148
+ else:
149
+ font = ImageFont.load_default(size=font_size)
150
+
151
+ text_bbox = draw.textbbox((0, 0), text, font=font)
152
+ text_width, text_height = text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1]
153
+ x = width - text_width - 10
154
+ y = height - text_height - 20
155
+
156
+ shadow_offset = 2
157
+ shadow_color = "black"
158
+ draw.text((x + shadow_offset, y + shadow_offset), text, font=font, fill=shadow_color)
159
+
160
+ draw.text((x, y), text, font=font, fill="white")
161
+
162
+ return image
163
+
164
+
165
  @spaces.GPU(duration=120)
166
  def generate_image(
167
  input_image,
 
198
  infusenet_guidance_start=infusenet_guidance_start,
199
  infusenet_guidance_end=infusenet_guidance_end,
200
  )
201
+ image = add_safety_watermark(image)
202
  except Exception as e:
203
  print(e)
204
  gr.Error(f"An error occurred: {e}")
 
212
 
213
 
214
  sample_list = [
215
+ ['./assets/examples/man.jpg', None, 'A sophisticated gentleman exuding confidence. He is dressed in a 1990s brown plaid jacket with a high collar, paired with a dark grey turtleneck. His trousers are tailored and charcoal in color, complemented by a sleek leather belt. The background showcases an elegant library with bookshelves, a marble fireplace, and warm lighting, creating a refined and cozy atmosphere. His relaxed posture and casual hand-in-pocket stance add to his composed and stylish demeanor', 666, False, False, 'aes_stage2'],
216
+ ['./assets/examples/man.jpg', './assets/examples/man_pose.jpg', 'A man, portrait, cinematic', 42, True, False, 'aes_stage2'],
217
+ ['./assets/examples/man.jpg', None, 'A man, portrait, cinematic', 12345, False, False, 'sim_stage1'],
218
+ ['./assets/examples/woman.jpg', './assets/examples/woman.jpg', 'A woman, portrait, cinematic', 1621695706, False, False, 'sim_stage1'],
219
+ ['./assets/examples/woman.jpg', None, 'A young woman holding a sign with the text "InfiniteYou", "Infinite" in black and "You" in red, pure background', 3724009365, False, False, 'aes_stage2'],
220
+ ['./assets/examples/woman.jpg', None, 'A photo of an elegant Javanese bride in traditional attire, with long hair styled into intricate a braid made of many fresh flowers, wearing a delicate headdress made from sequins and beads. She\'s holding flowers, light smiling at the camera, against a backdrop adorned with orchid blooms. The scene captures her grace as she stands amidst soft pastel colors, adding to its dreamy atmosphere', 42, True, False, 'aes_stage2'],
221
+ ['./assets/examples/woman.jpg', None, 'A photo of an elegant Javanese bride in traditional attire, with long hair styled into intricate a braid made of many fresh flowers, wearing a delicate headdress made from sequins and beads. She\'s holding flowers, light smiling at the camera, against a backdrop adorned with orchid blooms. The scene captures her grace as she stands amidst soft pastel colors, adding to its dreamy atmosphere', 42, False, False, 'sim_stage1'],
222
  ]
223
 
224
  with gr.Blocks() as demo:
 
330
  """
331
  ---
332
  ### 📜 Disclaimer and Licenses
333
+ The images used in this demo are sourced from consented subjects or generated by the models. These pictures are intended solely to show the capabilities of our research. If you have any concerns, please contact us, and we will promptly remove any inappropriate content.
334
 
335
  The use of the released code, model, and demo must strictly adhere to the respective licenses.
336
  Our code is released under the [Apache 2.0 License](https://github.com/bytedance/InfiniteYou/blob/main/LICENSE),
 
338
  for academic research purposes only. Any manual or automatic downloading of the face models from [InsightFace](https://github.com/deepinsight/insightface),
339
  the [FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev) base model, LoRAs, *etc.*, must follow their original licenses and be used only for academic research purposes.
340
 
341
+ This research aims to positively impact the field of Generative AI. Any usage of this method must be responsible and comply with local laws. The developers do not assume any responsibility for any potential misuse. We added the "AI Generated" watermark for enhanced safety.
342
  """
343
  )
344
 
assets/examples/yangmi.jpg DELETED
Binary file (414 kB)
 
assets/examples/yann-lecun_resize.jpg DELETED
Binary file (30.6 kB)