Yaron Koresh commited on
Commit
70bd56f
·
verified ·
1 Parent(s): 98ac56e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -25,7 +25,7 @@ from diffusers.utils import export_to_gif, load_image
25
  from huggingface_hub import hf_hub_download
26
  from safetensors.torch import load_file, save_file
27
  from diffusers import AnimateDiffPipeline, MotionAdapter, DDIMScheduler, StableDiffusionPipeline
28
- from PIL import Image, ImageDraw
29
 
30
  # logging
31
 
@@ -123,12 +123,6 @@ pipe.enable_free_init(method="butterworth", use_fast_sampling=fast)
123
 
124
  # functionality
125
 
126
- def textsize(text):
127
- im = Image.new(mode="P", size=(0, 0))
128
- draw = ImageDraw.Draw(im)
129
- _, _, width, height = draw.textbbox((0, 0), text=text)
130
- return width, height
131
-
132
  def run(cmd):
133
  return str(subprocess.run(cmd, shell=True, capture_output=True, env=None).stdout)
134
 
@@ -247,11 +241,12 @@ def handle_generate(*_inp):
247
 
248
  if inp[5] != "":
249
  draw = ImageDraw.Draw(pipe_out)
250
- textwidth, textheight = textsize(inp[5])
251
- margin = 10
252
- x = width - textwidth - margin
253
- y = height - textheight - margin
254
- draw.text((x, y), inp[5])
 
255
 
256
  name = generate_random_string(12) + ( ".png" if time == 0 else ".gif" )
257
  if inp[4] == 0.0:
 
25
  from huggingface_hub import hf_hub_download
26
  from safetensors.torch import load_file, save_file
27
  from diffusers import AnimateDiffPipeline, MotionAdapter, DDIMScheduler, StableDiffusionPipeline
28
+ from PIL import Image, ImageDraw, ImageFont
29
 
30
  # logging
31
 
 
123
 
124
  # functionality
125
 
 
 
 
 
 
 
126
  def run(cmd):
127
  return str(subprocess.run(cmd, shell=True, capture_output=True, env=None).stdout)
128
 
 
241
 
242
  if inp[5] != "":
243
  draw = ImageDraw.Draw(pipe_out)
244
+ textheight=32
245
+ font = ImageFont.truetype(r"OpenSans-Bold.ttf", textheight)
246
+ textwidth = draw.textlength(inp[5])
247
+ x = (width - textwidth) // 2
248
+ y = (height - textheight) // 2
249
+ draw.text((x, y), inp[5],font=font)
250
 
251
  name = generate_random_string(12) + ( ".png" if time == 0 else ".gif" )
252
  if inp[4] == 0.0: