phenixrhyder commited on
Commit
74e3d38
·
unverified ·
1 Parent(s): def0e97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -11,8 +11,8 @@ def create_checkerboard(board_size, square_size, color1, color2):
11
  Args:
12
  board_size (int): The number of squares per side.
13
  square_size (int): The size of each square in pixels.
14
- color1 (str): The hex code for the first color.
15
- color2 (str): The hex code for the second color.
16
 
17
  Returns:
18
  (PIL.Image.Image, str): A tuple containing the generated image
@@ -53,17 +53,20 @@ def create_checkerboard(board_size, square_size, color1, color2):
53
  # --- Create the Gradio Interface ---
54
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
55
  gr.Markdown("# Checkerboard Pattern Generator")
56
- gr.Markdown("Use the sliders and color pickers to customize your pattern, then click Generate.")
57
 
58
  with gr.Row():
59
  # Input sliders for customization
60
  board_size_slider = gr.Slider(minimum=2, maximum=20, value=8, step=1, label="Board Size (e.g., 8x8)")
61
  square_size_slider = gr.Slider(minimum=10, maximum=100, value=50, step=5, label="Square Size (pixels)")
62
 
 
 
 
63
  with gr.Row():
64
- # NEW: Color pickers for the two board colors
65
- color_picker_1 = gr.ColorPicker(value="#FFFFFF", label="Color 1 (Light)")
66
- color_picker_2 = gr.ColorPicker(value="#000000", label="Color 2 (Dark)")
67
 
68
  # The button to trigger the image generation
69
  generate_button = gr.Button("Generate Image")
@@ -71,14 +74,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
71
  # The output component to display the generated image
72
  output_image = gr.Image(label="Generated Checkerboard")
73
 
74
- # NEW: The file component for the download button
75
  download_button = gr.File(label="Download Image as PNG")
76
 
77
  # Link the button to the function
78
  generate_button.click(
79
  fn=create_checkerboard,
80
- inputs=[board_size_slider, square_size_slider, color_picker_1, color_picker_2],
81
- outputs=[output_image, download_button] # We now have two outputs
82
  )
83
 
84
  # --- Launch the App ---
 
11
  Args:
12
  board_size (int): The number of squares per side.
13
  square_size (int): The size of each square in pixels.
14
+ color1 (str): The name or hex code for the first color.
15
+ color2 (str): The name or hex code for the second color.
16
 
17
  Returns:
18
  (PIL.Image.Image, str): A tuple containing the generated image
 
53
  # --- Create the Gradio Interface ---
54
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
55
  gr.Markdown("# Checkerboard Pattern Generator")
56
+ gr.Markdown("Use the sliders and dropdowns to customize your pattern, then click Generate.")
57
 
58
  with gr.Row():
59
  # Input sliders for customization
60
  board_size_slider = gr.Slider(minimum=2, maximum=20, value=8, step=1, label="Board Size (e.g., 8x8)")
61
  square_size_slider = gr.Slider(minimum=10, maximum=100, value=50, step=5, label="Square Size (pixels)")
62
 
63
+ # Define a list of standard colors for the dropdowns
64
+ color_choices = ["White", "Black", "Gray", "Red", "Green", "Blue", "Yellow", "Purple", "Orange", "Cyan", "Magenta"]
65
+
66
  with gr.Row():
67
+ # CHANGED: Replaced ColorPickers with Dropdowns for reliability
68
+ dropdown_1 = gr.Dropdown(choices=color_choices, value="White", label="Color 1 (Light)")
69
+ dropdown_2 = gr.Dropdown(choices=color_choices, value="Black", label="Color 2 (Dark)")
70
 
71
  # The button to trigger the image generation
72
  generate_button = gr.Button("Generate Image")
 
74
  # The output component to display the generated image
75
  output_image = gr.Image(label="Generated Checkerboard")
76
 
77
+ # The file component for the download button
78
  download_button = gr.File(label="Download Image as PNG")
79
 
80
  # Link the button to the function
81
  generate_button.click(
82
  fn=create_checkerboard,
83
+ inputs=[board_size_slider, square_size_slider, dropdown_1, dropdown_2], # Using dropdowns as inputs now
84
+ outputs=[output_image, download_button]
85
  )
86
 
87
  # --- Launch the App ---