File size: 1,664 Bytes
a3a7e9a
 
1604608
a3a7e9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1604608
a3a7e9a
1604608
 
 
 
 
 
a3a7e9a
63e9391
a3a7e9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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()