halimbahae commited on
Commit
95da0b4
·
verified ·
1 Parent(s): c98eb2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -32
app.py CHANGED
@@ -3,6 +3,8 @@ import numpy as np
3
  import random
4
  from diffusers import DiffusionPipeline
5
  import torch
 
 
6
 
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
 
@@ -18,26 +20,6 @@ else:
18
  MAX_SEED = np.iinfo(np.int32).max
19
  MAX_IMAGE_SIZE = 3072
20
 
21
- # def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
22
-
23
- # if randomize_seed:
24
- # seed = random.randint(0, MAX_SEED)
25
-
26
- # generator = torch.Generator().manual_seed(seed)
27
-
28
- # image = pipe(
29
- # prompt = prompt,
30
- # negative_prompt = negative_prompt,
31
- # guidance_scale = guidance_scale,
32
- # num_inference_steps = num_inference_steps,
33
- # width = width,
34
- # height = height,
35
- # generator = generator
36
- # ).images[0]
37
-
38
- # return image
39
-
40
-
41
 
42
  def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
43
  # Append Moroccan and Amazigh art styles to the prompt
@@ -45,20 +27,35 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
45
 
46
  if randomize_seed:
47
  seed = random.randint(0, MAX_SEED)
48
-
49
  generator = torch.Generator().manual_seed(seed)
50
-
51
  image = pipe(
52
- prompt = style_prompt,
53
- negative_prompt = negative_prompt,
54
- guidance_scale = guidance_scale,
55
- num_inference_steps = num_inference_steps,
56
- width = width,
57
- height = height,
58
- generator = generator
59
- ).images[0]
60
-
61
- return image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
 
64
 
 
3
  import random
4
  from diffusers import DiffusionPipeline
5
  import torch
6
+ from PIL import Image, ImageDraw, ImageFont
7
+
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
 
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 3072
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
25
  # Append Moroccan and Amazigh art styles to the prompt
 
27
 
28
  if randomize_seed:
29
  seed = random.randint(0, MAX_SEED)
30
+
31
  generator = torch.Generator().manual_seed(seed)
32
+
33
  image = pipe(
34
+ prompt=style_prompt,
35
+ negative_prompt=negative_prompt,
36
+ guidance_scale=guidance_scale,
37
+ num_inference_steps=num_inference_steps,
38
+ width=width,
39
+ height=height,
40
+ generator=generator
41
+ ).images[0]
42
+
43
+ # Convert the image to PIL format for overlaying the watermark
44
+ pil_image = Image.fromarray(image)
45
+
46
+ # Add watermark
47
+ watermark_text = "Bibou.jpeg"
48
+ font = ImageFont.truetype("arial.ttf", size=30) # Adjust font and size as needed
49
+ draw = ImageDraw.Draw(pil_image)
50
+ text_width, text_height = draw.textsize(watermark_text, font=font)
51
+ margin = 10
52
+ opacity = 0.6
53
+ draw.text((pil_image.width - text_width - margin, pil_image.height - text_height - margin), watermark_text, font=font, fill=(255, 255, 255, int(255 * opacity)))
54
+
55
+ # Convert back to numpy array for Gradio display
56
+ watermarked_image = np.array(pil_image)
57
+
58
+ return watermarked_image
59
 
60
 
61