VirtualOasis commited on
Commit
baaef04
·
verified ·
1 Parent(s): 6418207

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -25,7 +25,7 @@ def draw_lattice_grid(draw, width, height, spacing=100, color=(235, 235, 235)):
25
  draw.line([(0, y), (width, y)], fill=color, width=2)
26
 
27
 
28
- def text_to_images_and_base64_generator(text_content, style, font_size, bg_color_name):
29
  """
30
  Converts text into images, returning both PIL objects for UI preview
31
  and base64 strings for an API/MCP client, with customizable options.
@@ -35,6 +35,7 @@ def text_to_images_and_base64_generator(text_content, style, font_size, bg_color
35
  style (str): The background style ('plain', 'lines', 'dots', 'grid').
36
  font_size (int): The font size for the text.
37
  bg_color_name (str): The name of the background color.
 
38
 
39
  Returns:
40
  tuple: A tuple containing (list of PIL.Image.Image, list of base64 strings).
@@ -43,21 +44,25 @@ def text_to_images_and_base64_generator(text_content, style, font_size, bg_color
43
  gr.Warning("Input text is empty. Please enter some text to generate images.")
44
  return [], []
45
 
46
- # --- Color Mapping ---
 
 
 
 
 
 
47
  color_map = {
48
  "White": (255, 255, 255),
49
  "Light Gray": (240, 240, 240),
50
  "Beige": (245, 245, 220),
51
  "Pale Blue": (220, 230, 245)
52
  }
 
53
  BACKGROUND_COLOR = color_map.get(bg_color_name, (255, 255, 255))
54
 
55
  # --- Configuration ---
56
- IMG_WIDTH = 1080
57
- IMG_HEIGHT = 1080
58
  TEXT_COLOR = (10, 10, 10)
59
  STYLE_COLOR = (225, 225, 225)
60
-
61
  PADDING_X = 80
62
  PADDING_Y = 80
63
  LINE_SPACING = 20
@@ -185,7 +190,8 @@ demo = gr.Interface(
185
  gr.Textbox(lines=10, label="Text Content", placeholder="Paste your long-form text here...", value=example_text),
186
  gr.Radio(['lines', 'dots', 'grid', 'plain'], label="Background Style", value='lines'),
187
  gr.Slider(24, 72, value=48, step=2, label="Font Size"),
188
- gr.Radio(["White", "Light Gray", "Beige", "Pale Blue"], label="Background Color", value="White")
 
189
  ],
190
  outputs=[
191
  gr.Gallery(label="Generated Images (Preview)", show_label=True, preview=True),
 
25
  draw.line([(0, y), (width, y)], fill=color, width=2)
26
 
27
 
28
+ def text_to_images_and_base64_generator(text_content, style, font_size, bg_color_name, aspect_ratio_str):
29
  """
30
  Converts text into images, returning both PIL objects for UI preview
31
  and base64 strings for an API/MCP client, with customizable options.
 
35
  style (str): The background style ('plain', 'lines', 'dots', 'grid').
36
  font_size (int): The font size for the text.
37
  bg_color_name (str): The name of the background color.
38
+ aspect_ratio_str (str): The string representing the desired aspect ratio.
39
 
40
  Returns:
41
  tuple: A tuple containing (list of PIL.Image.Image, list of base64 strings).
 
44
  gr.Warning("Input text is empty. Please enter some text to generate images.")
45
  return [], []
46
 
47
+ # --- Aspect Ratio and Color Mapping ---
48
+ aspect_ratio_map = {
49
+ "1:1 (Square)": (1080, 1080),
50
+ "16:9 (Widescreen)": (1080, 608),
51
+ "9:16 (Vertical)": (1080, 1920),
52
+ "4:3 (Standard)": (1080, 810)
53
+ }
54
  color_map = {
55
  "White": (255, 255, 255),
56
  "Light Gray": (240, 240, 240),
57
  "Beige": (245, 245, 220),
58
  "Pale Blue": (220, 230, 245)
59
  }
60
+ IMG_WIDTH, IMG_HEIGHT = aspect_ratio_map.get(aspect_ratio_str, (1080, 1080))
61
  BACKGROUND_COLOR = color_map.get(bg_color_name, (255, 255, 255))
62
 
63
  # --- Configuration ---
 
 
64
  TEXT_COLOR = (10, 10, 10)
65
  STYLE_COLOR = (225, 225, 225)
 
66
  PADDING_X = 80
67
  PADDING_Y = 80
68
  LINE_SPACING = 20
 
190
  gr.Textbox(lines=10, label="Text Content", placeholder="Paste your long-form text here...", value=example_text),
191
  gr.Radio(['lines', 'dots', 'grid', 'plain'], label="Background Style", value='lines'),
192
  gr.Slider(24, 72, value=48, step=2, label="Font Size"),
193
+ gr.Radio(["White", "Light Gray", "Beige", "Pale Blue"], label="Background Color", value="White"),
194
+ gr.Radio(["1:1 (Square)", "16:9 (Widescreen)", "9:16 (Vertical)", "4:3 (Standard)"], label="Aspect Ratio", value="1:1 (Square)")
195
  ],
196
  outputs=[
197
  gr.Gallery(label="Generated Images (Preview)", show_label=True, preview=True),