Sartc commited on
Commit
3b67773
·
verified ·
1 Parent(s): eb2a02a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -10,7 +10,7 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
  weights_path = "unet_model.pth"
11
  model = load_model(weights_path, device)
12
 
13
- def process_image(image, text, font_size):
14
  image = image.convert("RGB")
15
  print(f"image: {image}")
16
  background_with_text = image.copy()
@@ -19,7 +19,8 @@ def process_image(image, text, font_size):
19
  font_path = os.path.join(current_dir, "FreeSansBold.ttf")
20
  font = ImageFont.truetype(font_path, font_size)
21
  text_position = (50, 50)
22
- text_color = (0, 0, 0)
 
23
  draw.text(text_position, text, fill=text_color, font=font)
24
 
25
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -46,7 +47,8 @@ interface = gr.Interface(
46
  inputs=[
47
  gr.Image(type="pil", label="Upload Image"),
48
  gr.Textbox(label="Enter Text"),
49
- gr.Slider(10, 70, value=5, step=5, label="Font Size")
 
50
  ],
51
  outputs=gr.Image(type="pil", label="Output Image"),
52
  title="Text Behind Image Generator",
 
10
  weights_path = "unet_model.pth"
11
  model = load_model(weights_path, device)
12
 
13
+ def process_image(image, text, font_size, text_color):
14
  image = image.convert("RGB")
15
  print(f"image: {image}")
16
  background_with_text = image.copy()
 
19
  font_path = os.path.join(current_dir, "FreeSansBold.ttf")
20
  font = ImageFont.truetype(font_path, font_size)
21
  text_position = (50, 50)
22
+ # text_color = (0, 0, 0)
23
+ text_color = tuple(int(text_color[i:i+2], 16) for i in (1, 3, 5))
24
  draw.text(text_position, text, fill=text_color, font=font)
25
 
26
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
47
  inputs=[
48
  gr.Image(type="pil", label="Upload Image"),
49
  gr.Textbox(label="Enter Text"),
50
+ gr.Slider(10, 70, value=5, step=5, label="Font Size"),
51
+ gr.ColorPicker(value="#000000", label="Text Color")
52
  ],
53
  outputs=gr.Image(type="pil", label="Output Image"),
54
  title="Text Behind Image Generator",