Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import random | |
| from PIL import Image, ImageDraw | |
| def smooth_color(color, threshold): | |
| if color == " ": | |
| return random.choice(["FF0000", "32FF00", "00FFFF", "FFFFFF", "000000"]) | |
| return color | |
| def generate_color(prompt): | |
| color_red = " " | |
| color_green = " " | |
| color_blue = " " | |
| color_white = " " | |
| color_none = " " | |
| red = ['e', 'f', 'g', 'i', 'j', 'k', 'm', 'n', 'p', 'r'] | |
| green = ['c', 'd', 'h', 'l', 'o', 'q', 's', 'u', 'y', 'w'] | |
| blue = ['a', 'b', 't', 'v', 'x', 'z'] | |
| sym = ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "<", ">", "/", "'", "-", "+", "="] | |
| redded = [] | |
| greened = [] | |
| blued = [] | |
| whited = [] | |
| nothing = [] | |
| for letter in prompt: | |
| if letter in red: | |
| redded.append(letter) | |
| elif letter in green: | |
| greened.append(letter) | |
| elif letter in blue: | |
| blued.append(letter) | |
| elif letter == " ": | |
| whited.append(random.choice(sym)) | |
| else: | |
| nothing.append(letter) | |
| color_red = smooth_color(color_red, len(redded)) | |
| color_green = smooth_color(color_green, len(greened)) | |
| color_blue = smooth_color(color_blue, len(blued)) | |
| color_white = smooth_color(color_white, len(whited)) | |
| color_none = smooth_color(color_none, len(nothing)) | |
| # Convert the color to an image using PIL | |
| image = Image.new('RGB', (100, 100), color="#"+color_red+color_green+color_blue) | |
| draw = ImageDraw.Draw(image) | |
| draw.text((20, 40), "".join(whited), fill="#"+color_white) | |
| return image | |
| iface = gr.Interface(generate_color, "text", "image", theme="soft") | |
| iface.launch() | |