BertChristiaens commited on
Commit
0cae6b6
1 Parent(s): 2ea3bd8

change order

Browse files
Files changed (2) hide show
  1. app.py +14 -13
  2. config.py +12 -3
app.py CHANGED
@@ -100,7 +100,7 @@ def make_prompt_row():
100
  def make_sidebar():
101
  with st.sidebar:
102
  input_image = st.file_uploader("", type=["png", "jpg"], key='input_image', on_change=on_upload)
103
- generation_mode = st.selectbox("Generation mode", ["Inpainting", "Segmentation conditioning"], on_change=on_change_radio)
104
 
105
  paint_mode = st.sidebar.selectbox("Painting mode", ("freedraw", "polygon"))
106
  if paint_mode == "freedraw":
@@ -152,18 +152,19 @@ def make_editing_canvas(canvas_color, brush, _reset_state, generation_mode, pain
152
  **canvas_dict,
153
  )
154
  if 'seg' not in st.session_state:
155
- image = get_image()
156
- print("Preparing image segmentation")
157
- real_seg = segment_image(Image.fromarray(image))
158
- st.session_state['seg'] = real_seg
159
- # get unique RGB colors from this segmentation map
160
- unique_colors = np.unique(real_seg.reshape(-1, real_seg.shape[2]), axis=0)
161
- st.session_state['unique_colors'] = unique_colors
162
- # multiselect to choose multiple colors
163
- chosen_colors = st.multiselect(
164
- "Choose colors", list(unique_colors), format_func=map_colors, key='chosen_colors'
165
- )
166
- print(chosen_colors)
 
167
 
168
  if st.button("generate image", key='generate_button'):
169
  image = get_image()
 
100
  def make_sidebar():
101
  with st.sidebar:
102
  input_image = st.file_uploader("", type=["png", "jpg"], key='input_image', on_change=on_upload)
103
+ generation_mode = st.selectbox("Generation mode", ["Segmentation conditioning", "Inpainting"], on_change=on_change_radio)
104
 
105
  paint_mode = st.sidebar.selectbox("Painting mode", ("freedraw", "polygon"))
106
  if paint_mode == "freedraw":
 
152
  **canvas_dict,
153
  )
154
  if 'seg' not in st.session_state:
155
+ with st.spinner(text="Preparing image segmentation"):
156
+ image = get_image()
157
+ print("Preparing image segmentation")
158
+ real_seg = segment_image(Image.fromarray(image))
159
+ st.session_state['seg'] = real_seg
160
+ # get unique RGB colors from this segmentation map
161
+ unique_colors = np.unique(real_seg.reshape(-1, real_seg.shape[2]), axis=0)
162
+ st.session_state['unique_colors'] = unique_colors
163
+ # multiselect to choose multiple colors
164
+ chosen_colors = st.multiselect(
165
+ "Choose colors", list(unique_colors), format_func=map_colors, key='chosen_colors'
166
+ )
167
+ print(chosen_colors)
168
 
169
  if st.button("generate image", key='generate_button'):
170
  image = get_image()
config.py CHANGED
@@ -4,10 +4,19 @@ from palette import COLOR_MAPPING_, COLOR_MAPPING
4
  HEIGHT = 512
5
  WIDTH = 512
6
 
7
- COLOR_NAMES = list(COLOR_MAPPING.keys())
8
- COLOR_RGB = [tuple(int(k[i:i+2], 16) for i in (1, 3, 5)) for k in COLOR_MAPPING_.keys()] + [(0, 0, 0), (255, 255, 255)]
9
- INVERSE_COLORS = {v: k for k, v in COLOR_MAPPING_.items()}
 
 
 
 
 
10
 
 
 
 
 
11
 
12
  def map_colors(color: str) -> str:
13
  """Map color to hex value.
 
4
  HEIGHT = 512
5
  WIDTH = 512
6
 
7
+ def to_rgb(color: str) -> tuple:
8
+ """Convert hex color to rgb.
9
+ Args:
10
+ color (str): hex color
11
+ Returns:
12
+ tuple: rgb color
13
+ """
14
+ return tuple(int(color[i:i+2], 16) for i in (1, 3, 5))
15
 
16
+ COLOR_NAMES = list(COLOR_MAPPING.keys())
17
+ COLOR_RGB = [to_rgb(k) for k in COLOR_MAPPING_.keys()] + [(0, 0, 0), (255, 255, 255)]
18
+ INVERSE_COLORS = {v: to_rgb(k) for k, v in COLOR_MAPPING_.items()}
19
+ COLOR_MAPPING_RGB = {to_rgb(k): v for k, v in COLOR_MAPPING_.items()}
20
 
21
  def map_colors(color: str) -> str:
22
  """Map color to hex value.