yashvii commited on
Commit
4f7d294
1 Parent(s): 14c8ffd

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. gradio_demo/app.py +45 -1
gradio_demo/app.py CHANGED
@@ -208,6 +208,47 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
208
  # def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
209
  # p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
210
  # return p.replace("{prompt}", positive), n + ' ' + negative
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
  def generate_image(face_image,prompt,negative_prompt):
213
  pose_image_path = None
@@ -298,8 +339,11 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
298
  generator=generator,
299
  # num_images_per_prompt = 4
300
  ).images
 
 
301
 
302
- return images[0]
 
303
 
304
  ### Description
305
  title = r"""
 
208
  # def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
209
  # p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
210
  # return p.replace("{prompt}", positive), n + ' ' + negative
211
+
212
+ def add_watermark(image, watermark=logo, opacity=128, position="bottom_right", padding=10):
213
+ # Convert NumPy array to PIL Image if needed
214
+ if isinstance(image, np.ndarray):
215
+ image = Image.fromarray(image)
216
+
217
+ if isinstance(watermark, np.ndarray):
218
+ watermark = Image.fromarray(watermark)
219
+
220
+ # Convert images to 'RGBA' mode to handle transparency
221
+ image = image.convert("RGBA")
222
+ watermark = watermark.convert("RGBA")
223
+
224
+ # Adjust the watermark opacity
225
+ watermark = watermark.copy()
226
+ watermark.putalpha(opacity)
227
+
228
+ # Calculate the position for the watermark
229
+ if position == "bottom_right":
230
+ x = image.width - watermark.width - padding
231
+ y = image.height - watermark.height - padding
232
+ elif position == "bottom_left":
233
+ x = padding
234
+ y = image.height - watermark.height - padding
235
+ elif position == "top_right":
236
+ x = image.width - watermark.width - padding
237
+ y = padding
238
+ elif position == "top_left":
239
+ x = padding
240
+ y = padding
241
+ else:
242
+ raise ValueError("Unsupported position. Choose from 'bottom_right', 'bottom_left', 'top_right', 'top_left'.")
243
+
244
+ # Paste the watermark onto the image
245
+ image.paste(watermark, (x, y), watermark)
246
+
247
+ # Convert back to 'RGB' if the original image was not 'RGBA'
248
+ if image.mode != "RGBA":
249
+ image = image.convert("RGB")
250
+
251
+ return image
252
 
253
  def generate_image(face_image,prompt,negative_prompt):
254
  pose_image_path = None
 
339
  generator=generator,
340
  # num_images_per_prompt = 4
341
  ).images
342
+
343
+ watermarked_image = add_watermark(images[0])
344
 
345
+ # return images[0]
346
+ return watermarked_image
347
 
348
  ### Description
349
  title = r"""