francescoKrnl commited on
Commit
c6dc013
β€’
1 Parent(s): 1ffaa25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -21,12 +21,11 @@ ITEMS_NAMES = [ "πŸ’‘ Lamp","πŸ‘œ Bag","πŸ›‹οΈ Sofa","πŸͺ‘ Chair","🏎️ Car"
21
  MAX_SEED = np.iinfo(np.int32).max
22
  DEFAULT_ITEM_NAME = "πŸ’‘ Lamp"
23
  COLORS = ["blue", "red", "black", "yellow", "green", "pink", "grey"]
24
- SELECTED_COLOR = random.choice(COLORS)
25
  def empty_input_image():
26
- SELECTED_COLOR = random.choice(COLORS)
27
- return { 'background': Image.new("L", (512, 512), 255),
28
  'layers': [Image.new("L", (512, 512), 255),Image.new("L", (512, 512), 255)],
29
- 'composite': Image.new("L", (512, 512), 255)}
30
 
31
  def pil_image_to_data_uri(img, format='PNG'):
32
  buffered = BytesIO()
@@ -35,7 +34,7 @@ def pil_image_to_data_uri(img, format='PNG'):
35
  return f"data:image/{format.lower()};base64,{img_str}"
36
 
37
 
38
- def run(image, item_name):
39
  print("sketch updated")
40
  print(image)
41
  empty_image = Image.new("L", (512, 512), 255)
@@ -45,7 +44,7 @@ def run(image, item_name):
45
  ones = empty_image
46
  return ones
47
  print(item_name.split()[1])
48
- prompt = SELECTED_COLOR + " " + item_name.split()[1] + " professional 3d model. octane render, highly detailed, volumetric, dramatic lighting"
49
  inverted_image = ImageOps.invert(image["composite"])
50
  converted_image = inverted_image.convert("RGB")
51
  image_t = TF.to_tensor(converted_image) > 0.5
@@ -195,14 +194,16 @@ with gr.Blocks(css="style.css", head = head) as demo:
195
  </button>""",elem_id="eraser_container")
196
  with gr.Group(elem_id="output_image_container", elem_classes="image_container"):
197
  result = gr.Image(label="Result", height="100%", width="100%", elem_id="output_image", show_label=False, show_download_button=True,container=False,)
 
198
  with gr.Row(elem_id="radio_row"):
199
- item = gr.Radio(choices=ITEMS_NAMES, value=DEFAULT_ITEM_NAME, show_label=False, container=False)
200
 
201
  demo.load(None,None,None,js=scripts)
202
- inputs = [image, item]
203
  outputs = [result]
204
  item.change(fn=run, inputs=inputs, outputs=outputs)
 
205
  image.change(fn=run, inputs=inputs, outputs=outputs, trigger_mode="always_last")
206
- image.clear(fn=empty_input_image, outputs=image)
207
  if __name__ == "__main__":
208
  demo.queue().launch(debug=True, allowed_paths=["."])
 
21
  MAX_SEED = np.iinfo(np.int32).max
22
  DEFAULT_ITEM_NAME = "πŸ’‘ Lamp"
23
  COLORS = ["blue", "red", "black", "yellow", "green", "pink", "grey"]
24
+ DEFAULT_COLOR = "yellow"
25
  def empty_input_image():
26
+ return [{ 'background': Image.new("L", (512, 512), 255),
 
27
  'layers': [Image.new("L", (512, 512), 255),Image.new("L", (512, 512), 255)],
28
+ 'composite': Image.new("L", (512, 512), 255)}, random.choice(COLORS)]
29
 
30
  def pil_image_to_data_uri(img, format='PNG'):
31
  buffered = BytesIO()
 
34
  return f"data:image/{format.lower()};base64,{img_str}"
35
 
36
 
37
+ def run(image, item_name, color_name):
38
  print("sketch updated")
39
  print(image)
40
  empty_image = Image.new("L", (512, 512), 255)
 
44
  ones = empty_image
45
  return ones
46
  print(item_name.split()[1])
47
+ prompt = color_name + " " + item_name.split()[1] + " professional 3d model. octane render, highly detailed, volumetric, dramatic lighting"
48
  inverted_image = ImageOps.invert(image["composite"])
49
  converted_image = inverted_image.convert("RGB")
50
  image_t = TF.to_tensor(converted_image) > 0.5
 
194
  </button>""",elem_id="eraser_container")
195
  with gr.Group(elem_id="output_image_container", elem_classes="image_container"):
196
  result = gr.Image(label="Result", height="100%", width="100%", elem_id="output_image", show_label=False, show_download_button=True,container=False,)
197
+ color = gr.Radio(choices=COLORS, value=DEFAULT_COLOR, show_label=False, container=False, visible=False)
198
  with gr.Row(elem_id="radio_row"):
199
+ item = gr.Radio(choices=ITEMS_NAMES, value=DEFAULT_ITEM_NAMEDEFAULT_COLOR, show_label=False, container=False)
200
 
201
  demo.load(None,None,None,js=scripts)
202
+ inputs = [image, item, color]
203
  outputs = [result]
204
  item.change(fn=run, inputs=inputs, outputs=outputs)
205
+ color.change(fn=run, inputs=inputs, outputs=outputs)
206
  image.change(fn=run, inputs=inputs, outputs=outputs, trigger_mode="always_last")
207
+ image.clear(fn=empty_input_image, outputs=[image , color])
208
  if __name__ == "__main__":
209
  demo.queue().launch(debug=True, allowed_paths=["."])