Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
|
4 |
+
def smooth_color(color, threshold):
|
5 |
+
if color == " ":
|
6 |
+
return random.choice(["FF0000", "32FF00", "00FFFF", "FFFFFF", "000000"])
|
7 |
+
return color
|
8 |
+
|
9 |
+
def generate_color(prompt):
|
10 |
+
color_red = " "
|
11 |
+
color_green = " "
|
12 |
+
color_blue = " "
|
13 |
+
color_white = " "
|
14 |
+
color_none = " "
|
15 |
+
|
16 |
+
red = ['e', 'f', 'g', 'i', 'j', 'k', 'm', 'n', 'p', 'r']
|
17 |
+
green = ['c', 'd', 'h', 'l', 'o', 'q', 's', 'u', 'y', 'w']
|
18 |
+
blue = ['a', 'b', 't', 'v', 'x', 'z']
|
19 |
+
sym = ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "<", ">", "/", "'", "-", "+", "="]
|
20 |
+
|
21 |
+
redded = []
|
22 |
+
greened = []
|
23 |
+
blued = []
|
24 |
+
whited = []
|
25 |
+
nothing = []
|
26 |
+
|
27 |
+
for letter in prompt:
|
28 |
+
if letter in red:
|
29 |
+
redded.append(letter)
|
30 |
+
elif letter in green:
|
31 |
+
greened.append(letter)
|
32 |
+
elif letter in blue:
|
33 |
+
blued.append(letter)
|
34 |
+
elif letter == " ":
|
35 |
+
whited.append(random.choice(sym))
|
36 |
+
else:
|
37 |
+
nothing.append(letter)
|
38 |
+
|
39 |
+
color_red = smooth_color(color_red, len(redded))
|
40 |
+
color_green = smooth_color(color_green, len(greened))
|
41 |
+
color_blue = smooth_color(color_blue, len(blued))
|
42 |
+
color_white = smooth_color(color_white, len(whited))
|
43 |
+
color_none = smooth_color(color_none, len(nothing))
|
44 |
+
|
45 |
+
return "#" + color_red + color_green + color_blue + color_white + color_none
|
46 |
+
|
47 |
+
iface = gr.Interface(generate_color, "text", "image", theme="soft",
|
48 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
49 |
+
outputs="image")
|
50 |
+
iface.launch()
|