salahIguiliz commited on
Commit
ae2743c
·
1 Parent(s): ec054fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -29
app.py CHANGED
@@ -54,17 +54,7 @@ controlnet = ControlNetModel.from_pretrained(
54
  pipe = StableDiffusionControlNetPipeline.from_pretrained(
55
  "runwayml/stable-diffusion-v1-5", controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16
56
  )
57
- pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
58
 
59
- # This command loads the individual model components on GPU on-demand. So, we don't
60
- # need to explicitly call pipe.to("cuda").
61
- pipe.enable_model_cpu_offload()
62
-
63
- # xformers
64
- pipe.enable_xformers_memory_efficient_attention()
65
-
66
- # Generator seed,
67
- generator = torch.manual_seed(0)
68
 
69
  def get_pose(image):
70
  return pose_model(image)
@@ -74,29 +64,21 @@ def get_pose(image):
74
  def generate_an_image_from_text(text, text_size_, width, lenght):
75
  # Create a blank image
76
  image = Image.new('RGB', (width, lenght), color = (255, 255, 255))
77
-
78
  # Create a drawing object
79
  draw = ImageDraw.Draw(image)
80
-
81
  # font def
82
  font_dir = '/usr/share/fonts/truetype/liberation/'
83
-
84
  # Get a list of all the font files in the directory
85
  font_files = [os.path.join(font_dir, f) for f in os.listdir(font_dir) if os.path.isfile(os.path.join(font_dir, f))]
86
-
87
  # Select a random font
88
  font_path = random.choice(font_files)
89
- print(font_path)
90
-
91
  font = ImageFont.truetype(font_path, text_size_)
92
-
93
  # Get the text size
94
  text_size = draw.textsize(text, font)
95
-
96
  # Calculate the x and y positions for the text
97
  x = (image.width - text_size[0]) / 2
98
  y = (image.height - text_size[1]) / 2
99
-
100
  # Draw the text on the image
101
  draw.text((x, y), text, fill=(0, 0, 0), font=font)
102
  return image
@@ -115,17 +97,20 @@ def to_Canny(image):
115
  return canny_image
116
 
117
  def inference(prompt,canny_image,number,seed ):
118
- pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
119
- pipe.to("cuda")
120
- #pipe.enable_model_cpu_offload()
121
- pipe.enable_xformers_memory_efficient_attention()
122
- generator = torch.manual_seed(seed)
123
-
124
- image_ = canny_image
125
- prompt = prompt
126
- out_image = pipe(
 
 
 
127
  prompt, num_inference_steps=20, generator=generator, image=image_, num_images_per_prompt=number)
128
- return out_image
129
 
130
  def generate_images(image, prompt):
131
  pose = get_pose(image)
 
54
  pipe = StableDiffusionControlNetPipeline.from_pretrained(
55
  "runwayml/stable-diffusion-v1-5", controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16
56
  )
 
57
 
 
 
 
 
 
 
 
 
 
58
 
59
  def get_pose(image):
60
  return pose_model(image)
 
64
  def generate_an_image_from_text(text, text_size_, width, lenght):
65
  # Create a blank image
66
  image = Image.new('RGB', (width, lenght), color = (255, 255, 255))
 
67
  # Create a drawing object
68
  draw = ImageDraw.Draw(image)
 
69
  # font def
70
  font_dir = '/usr/share/fonts/truetype/liberation/'
 
71
  # Get a list of all the font files in the directory
72
  font_files = [os.path.join(font_dir, f) for f in os.listdir(font_dir) if os.path.isfile(os.path.join(font_dir, f))]
 
73
  # Select a random font
74
  font_path = random.choice(font_files)
75
+ #print(font_path)
 
76
  font = ImageFont.truetype(font_path, text_size_)
 
77
  # Get the text size
78
  text_size = draw.textsize(text, font)
 
79
  # Calculate the x and y positions for the text
80
  x = (image.width - text_size[0]) / 2
81
  y = (image.height - text_size[1]) / 2
 
82
  # Draw the text on the image
83
  draw.text((x, y), text, fill=(0, 0, 0), font=font)
84
  return image
 
97
  return canny_image
98
 
99
  def inference(prompt,canny_image,number,seed ):
100
+
101
+ pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
102
+ # This command loads the individual model components on GPU on-demand. So, we don't
103
+ # need to explicitly call pipe.to("cuda").
104
+ pipe.enable_model_cpu_offload()
105
+ # xformers
106
+ pipe.enable_xformers_memory_efficient_attention()
107
+ # Generator seed,
108
+ generator = torch.manual_seed(seed)
109
+ image_ = canny_image
110
+ prompt = prompt
111
+ out_image = pipe(
112
  prompt, num_inference_steps=20, generator=generator, image=image_, num_images_per_prompt=number)
113
+ return out_image
114
 
115
  def generate_images(image, prompt):
116
  pose = get_pose(image)