hatmanstack commited on
Commit
a967c34
·
1 Parent(s): 8856d1e

reworked Color Guided

Browse files
Files changed (3) hide show
  1. app.py +7 -5
  2. functions.py +10 -7
  3. generate.py +1 -1
app.py CHANGED
@@ -28,7 +28,7 @@ with gr.Blocks() as demo:
28
  gr.HTML("""
29
  <style>
30
  #component-0 {
31
- max-width: 800px;
32
  margin: 0 auto;
33
  }
34
  .center-markdown {
@@ -147,15 +147,17 @@ with gr.Blocks() as demo:
147
  with gr.Column():
148
  gr.Markdown("""
149
  <div style="text-align: center;">
150
- Generate an image using a color palette. If you must include an image and text prompt, the subject and style will be used as a reference.
151
- The colors of the image will also be incorporated, along with the colors from the colors list. A color list is always required but one has been provided.
 
152
  </div>
153
  """)
154
- reference_image = gr.Image(type='pil', label="Reference Image")
155
  colors = gr.Textbox(label="Colors", placeholder="Enter up to 10 colors as hex values, e.g., #00FF00,#FCF2AB", max_lines=1)
156
-
157
  prompt = gr.Textbox(label="Text", placeholder="Enter a text prompt (1-1024 characters)", max_lines=4)
158
  gr.Button("Generate Prompt").click(generate_nova_prompt, outputs=prompt)
 
 
159
  error_box = gr.Markdown(visible=False, label="Error", elem_classes="center-markdown")
160
  output = gr.Image()
161
  with gr.Accordion("Advanced Options", open=False):
 
28
  gr.HTML("""
29
  <style>
30
  #component-0 {
31
+ max-width: 850px;
32
  margin: 0 auto;
33
  }
34
  .center-markdown {
 
147
  with gr.Column():
148
  gr.Markdown("""
149
  <div style="text-align: center;">
150
+ Generate an image using a color palette. You must include a text prompt if you choose to include an image, the subject and style will be used as a reference.
151
+ The colors of the image will also be incorporated, along with the colors from the colors list. A color list is also required if you choose not to include one,
152
+ a generic list has been provided.
153
  </div>
154
  """)
155
+
156
  colors = gr.Textbox(label="Colors", placeholder="Enter up to 10 colors as hex values, e.g., #00FF00,#FCF2AB", max_lines=1)
 
157
  prompt = gr.Textbox(label="Text", placeholder="Enter a text prompt (1-1024 characters)", max_lines=4)
158
  gr.Button("Generate Prompt").click(generate_nova_prompt, outputs=prompt)
159
+ with gr.Accordion("Optional Reference Image", open=False):
160
+ reference_image = gr.Image(type='pil', label="Reference Image")
161
  error_box = gr.Markdown(visible=False, label="Error", elem_classes="center-markdown")
162
  output = gr.Image()
163
  with gr.Accordion("Advanced Options", open=False):
functions.py CHANGED
@@ -166,19 +166,22 @@ def image_conditioning(condition_image, text, negative_text=None, control_mode="
166
  return check_return(result)
167
 
168
  def color_guided_content(text=None, reference_image=None, negative_text=None, colors=None, height=1024, width=1024, quality="standard", cfg_scale=8.0, seed=0):
169
- # Encode the reference image if provided
170
- reference_image_encoded = process_images(primary=reference_image)
171
- for value in reference_image_encoded.values():
172
- if len(value) < 200:
173
- return None, gr.update(visible=True, value=value)
174
-
 
 
 
175
  if not colors:
176
  colors = "#FF5733,#33FF57,#3357FF,#FF33A1,#33FFF5,#FF8C33,#8C33FF,#33FF8C,#FF3333,#33A1FF"
177
 
178
  color_guided_generation_params = {
179
  "text": text,
180
  "colors": colors.split(','),
181
- "referenceImage": reference_image_encoded.get('image'),
182
  **({"negativeText": negative_text} if negative_text not in [None, ""] else {})
183
  }
184
 
 
166
  return check_return(result)
167
 
168
  def color_guided_content(text=None, reference_image=None, negative_text=None, colors=None, height=1024, width=1024, quality="standard", cfg_scale=8.0, seed=0):
169
+ reference_image_str = None
170
+
171
+ if reference_image is not None and not isinstance(reference_image, type(None)):
172
+
173
+ reference_image_encoded = process_images(primary=reference_image)
174
+ for value in reference_image_encoded.values():
175
+ if len(value) < 200:
176
+ return None, gr.update(visible=True, value=value)
177
+ reference_image_str = reference_image_encoded.get('image')
178
  if not colors:
179
  colors = "#FF5733,#33FF57,#3357FF,#FF33A1,#33FFF5,#FF8C33,#8C33FF,#33FF8C,#FF3333,#33A1FF"
180
 
181
  color_guided_generation_params = {
182
  "text": text,
183
  "colors": colors.split(','),
184
+ **({"referenceImage": reference_image_str} if reference_image_str is not None else {}),
185
  **({"negativeText": negative_text} if negative_text not in [None, ""] else {})
186
  }
187
 
generate.py CHANGED
@@ -173,7 +173,7 @@ def check_rate_limit(body):
173
  raise ImageError(rate_limit_message.format('Premium'))
174
  rate_data['premium'].append(current_time)
175
  else: # standard
176
- if len(rate_data['standard']) >= 6:
177
  raise ImageError(rate_limit_message.format('Standard'))
178
  rate_data['standard'].append(current_time)
179
 
 
173
  raise ImageError(rate_limit_message.format('Premium'))
174
  rate_data['premium'].append(current_time)
175
  else: # standard
176
+ if len(rate_data['standard']) >= 12:
177
  raise ImageError(rate_limit_message.format('Standard'))
178
  rate_data['standard'].append(current_time)
179