Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,12 @@ import torch # the library
|
|
| 2 |
import torch.nn as nn # so we can just write nn.X insted of torch.nn.X
|
| 3 |
import gradio as gr
|
| 4 |
from PIL import ImageColor
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def parse_color_str(clrstr):
|
| 6 |
-
if clrstr[0]=='#': return clrstr #looks good already
|
| 7 |
if not clrstr.startswith('rgb'): # neither rgb(r,g,b) nor rgba(r,g,b,a)
|
| 8 |
gr.Warning(f"Unsupported color format: {clrstr}")
|
| 9 |
return "#000000"
|
|
@@ -63,6 +67,7 @@ def get_name(color,temp:float):
|
|
| 63 |
else:
|
| 64 |
color = (0,0,0)
|
| 65 |
name = "".join([vocab[_] for _ in model.name_color(torch.tensor([color])/255,color_pad_len,temp)]).strip()
|
|
|
|
| 66 |
return name.title()
|
| 67 |
|
| 68 |
demo = gr.Interface(
|
|
|
|
| 2 |
import torch.nn as nn # so we can just write nn.X insted of torch.nn.X
|
| 3 |
import gradio as gr
|
| 4 |
from PIL import ImageColor
|
| 5 |
+
def hex_to_rgb(value):
|
| 6 |
+
value = value.lstrip('#')
|
| 7 |
+
lv = len(value)
|
| 8 |
+
return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
|
| 9 |
def parse_color_str(clrstr):
|
| 10 |
+
if clrstr[0]=='#': return hex_to_rgb(clrstr) #looks good already
|
| 11 |
if not clrstr.startswith('rgb'): # neither rgb(r,g,b) nor rgba(r,g,b,a)
|
| 12 |
gr.Warning(f"Unsupported color format: {clrstr}")
|
| 13 |
return "#000000"
|
|
|
|
| 67 |
else:
|
| 68 |
color = (0,0,0)
|
| 69 |
name = "".join([vocab[_] for _ in model.name_color(torch.tensor([color])/255,color_pad_len,temp)]).strip()
|
| 70 |
+
print(f"Generated: {color} - {name.title()}")
|
| 71 |
return name.title()
|
| 72 |
|
| 73 |
demo = gr.Interface(
|