Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -30,18 +30,15 @@ def generate_ai_palette():
|
|
30 |
return [rgb_to_hex([random.randint(0, 255) for _ in range(3)]) for _ in range(5)]
|
31 |
|
32 |
# Function to update palette with user selection
|
33 |
-
def update_palette(image,
|
34 |
if image is not None:
|
35 |
-
selected_color = image[int(selected_y), int(selected_x)]
|
36 |
-
selected_hex = rgb_to_hex(selected_color)
|
37 |
-
|
38 |
colors = extract_colors(image, 5)
|
39 |
hex_colors = [rgb_to_hex(color) for color in colors]
|
40 |
|
41 |
# Replace unlocked colors with extracted ones
|
42 |
for i in range(5):
|
43 |
if locked_colors[i] == "":
|
44 |
-
locked_colors[i] =
|
45 |
else:
|
46 |
# If no image, generate AI colors
|
47 |
locked_colors = [color if color != "" else rgb_to_hex([random.randint(0, 255) for _ in range(3)]) for color in locked_colors]
|
@@ -70,13 +67,18 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
70 |
hex_output = gr.Textbox(label="Hex Codes", interactive=True)
|
71 |
|
72 |
with gr.Row():
|
73 |
-
locked_colors = [gr.Textbox(label=f"Color {i+1}", interactive=True) for i in range(5)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
generate_ai_button.click(generate_ai_palette, inputs=[], outputs=locked_colors)
|
76 |
regenerate_button.click(update_palette, inputs=[image_input, locked_colors], outputs=[palette_output, locked_colors])
|
77 |
-
|
78 |
-
image_input.select(update_palette, inputs=[image_input, image_input.select, image_input.select, locked_colors], outputs=[palette_output, locked_colors])
|
79 |
|
80 |
# Launch the app
|
81 |
if __name__ == "__main__":
|
82 |
-
iface.launch()
|
|
|
30 |
return [rgb_to_hex([random.randint(0, 255) for _ in range(3)]) for _ in range(5)]
|
31 |
|
32 |
# Function to update palette with user selection
|
33 |
+
def update_palette(image, locked_colors):
|
34 |
if image is not None:
|
|
|
|
|
|
|
35 |
colors = extract_colors(image, 5)
|
36 |
hex_colors = [rgb_to_hex(color) for color in colors]
|
37 |
|
38 |
# Replace unlocked colors with extracted ones
|
39 |
for i in range(5):
|
40 |
if locked_colors[i] == "":
|
41 |
+
locked_colors[i] = hex_colors[i]
|
42 |
else:
|
43 |
# If no image, generate AI colors
|
44 |
locked_colors = [color if color != "" else rgb_to_hex([random.randint(0, 255) for _ in range(3)]) for color in locked_colors]
|
|
|
67 |
hex_output = gr.Textbox(label="Hex Codes", interactive=True)
|
68 |
|
69 |
with gr.Row():
|
70 |
+
locked_colors = [gr.Textbox(label=f"Color {i+1}", interactive=True, value="") for i in range(5)]
|
71 |
+
|
72 |
+
# Initialize with a random palette on startup
|
73 |
+
initial_palette = generate_ai_palette()
|
74 |
+
initial_fig, initial_colors = update_palette(None, initial_palette)
|
75 |
+
palette_output.value = initial_fig
|
76 |
+
for i in range(5):
|
77 |
+
locked_colors[i].value = initial_colors[i]
|
78 |
|
79 |
generate_ai_button.click(generate_ai_palette, inputs=[], outputs=locked_colors)
|
80 |
regenerate_button.click(update_palette, inputs=[image_input, locked_colors], outputs=[palette_output, locked_colors])
|
|
|
|
|
81 |
|
82 |
# Launch the app
|
83 |
if __name__ == "__main__":
|
84 |
+
iface.launch()
|