angtrim commited on
Commit
de5fa74
1 Parent(s): a5f64c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -17,9 +17,9 @@ from src.pix2pix_turbo import Pix2Pix_Turbo
17
 
18
  model = Pix2Pix_Turbo("sketch_to_image_stochastic")
19
 
20
- OBJECTS_NAMES = [ "Lamp","Bag","Sofa","Chair","Car","Motorbike","Building"]
21
  MAX_SEED = np.iinfo(np.int32).max
22
- DEFAULT_OBJ_NAME = "Lamp"
23
 
24
 
25
  def pil_image_to_data_uri(img, format='PNG'):
@@ -29,13 +29,13 @@ def pil_image_to_data_uri(img, format='PNG'):
29
  return f"data:image/{format.lower()};base64,{img_str}"
30
 
31
 
32
- def run(image, prompt, prompt_template, style_name):
33
  print("sketch updated")
34
  if image is None:
35
  ones = Image.new("L", (512, 512), 255)
36
  temp_uri = pil_image_to_data_uri(ones)
37
  return ones, gr.update(link=temp_uri), gr.update(link=temp_uri)
38
- prompt = prompt_template.replace("{prompt}", prompt)
39
  image = image.convert("RGB")
40
  image_t = TF.to_tensor(image) > 0.5
41
  image_pil = TF.to_pil_image(image_t.to(torch.float32))
@@ -194,7 +194,7 @@ with gr.Blocks(css="style.css") as demo:
194
  </div>
195
  """)
196
  with gr.Row():
197
- object = gr.Dropdown(label="Object", choices=OBJECTS_NAMES, value=DEFAULT_OBJ_NAME, scale=1)
198
 
199
 
200
  with gr.Column(elem_id="column_output"):
@@ -207,11 +207,10 @@ with gr.Blocks(css="style.css") as demo:
207
  line.change(fn=lambda x: gr.update(value=not x), inputs=[line], outputs=[eraser]).then(update_canvas, [line, eraser], [image])
208
 
209
  demo.load(None,None,None,_js=scripts)
210
- prompt = object + "professional 3d model. octane render, highly detailed, volumetric, dramatic lighting"
211
- inputs = [image, prompt, prompt_temp, object]
212
  outputs = [result, download_sketch, download_output]
213
  #prompt.submit(fn=run, inputs=inputs, outputs=outputs)
214
- object.change(lambda x: objects[x], inputs=[object], outputs=[prompt_temp]).then(
215
  fn=run, inputs=inputs, outputs=outputs,)
216
  image.change(run, inputs=inputs, outputs=outputs,)
217
 
 
17
 
18
  model = Pix2Pix_Turbo("sketch_to_image_stochastic")
19
 
20
+ ITEMS_NAMES = [ "Lamp","Bag","Sofa","Chair","Car","Motorbike","Building"]
21
  MAX_SEED = np.iinfo(np.int32).max
22
+ DEFAULT_ITEM_NAME = "Lamp"
23
 
24
 
25
  def pil_image_to_data_uri(img, format='PNG'):
 
29
  return f"data:image/{format.lower()};base64,{img_str}"
30
 
31
 
32
+ def run(image, item_name):
33
  print("sketch updated")
34
  if image is None:
35
  ones = Image.new("L", (512, 512), 255)
36
  temp_uri = pil_image_to_data_uri(ones)
37
  return ones, gr.update(link=temp_uri), gr.update(link=temp_uri)
38
+ prompt = item_name + "professional 3d model. octane render, highly detailed, volumetric, dramatic lighting"
39
  image = image.convert("RGB")
40
  image_t = TF.to_tensor(image) > 0.5
41
  image_pil = TF.to_pil_image(image_t.to(torch.float32))
 
194
  </div>
195
  """)
196
  with gr.Row():
197
+ item = gr.Dropdown(label="Item", choices=ITEMS_NAMES, value=DEFAULT_ITEM_NAME, scale=1)
198
 
199
 
200
  with gr.Column(elem_id="column_output"):
 
207
  line.change(fn=lambda x: gr.update(value=not x), inputs=[line], outputs=[eraser]).then(update_canvas, [line, eraser], [image])
208
 
209
  demo.load(None,None,None,_js=scripts)
210
+ inputs = [image, object]
 
211
  outputs = [result, download_sketch, download_output]
212
  #prompt.submit(fn=run, inputs=inputs, outputs=outputs)
213
+ item.change(lambda x: objects[x], inputs=[item], outputs=[prompt_temp]).then(
214
  fn=run, inputs=inputs, outputs=outputs,)
215
  image.change(run, inputs=inputs, outputs=outputs,)
216