ysharma HF staff commited on
Commit
b896206
1 Parent(s): db84e12

update with synth image translte

Browse files
Files changed (1) hide show
  1. app.py +30 -8
app.py CHANGED
@@ -27,7 +27,17 @@ def image_edit(task_name, progress=gr.Progress(track_tqdm=True)):
27
  "--prompt", "output/test_cat/prompt/input_image.txt", "--task_name", task_name,
28
  "--results_folder", "output/test_cat/"])
29
  return "output/test_cat/edit/input_image.png"
30
-
 
 
 
 
 
 
 
 
 
 
31
  def set_visible_true():
32
  return gr.update(visible=True)
33
 
@@ -54,29 +64,41 @@ with gr.Blocks() as demo:
54
  Please visit their website and <a href="https://github.com/pix2pixzero/pix2pix-zero" target="_blank">github repo</a> for more details.
55
  </p></div>""")
56
  with gr.Row():
57
- image_in = gr.Image(type="pil", label="Start by uploading an image of a Cat or a Dog that you want to Translate")
58
  with gr.Column():
59
- btn_inversion = gr.Button("Get input noise and caption",visible=False )
60
  with gr.Row():
61
  blip_prompt = gr.Textbox(visible=False)
62
  inversion_file = gr.File(visible=False)
63
  #task_name = gr.Textbox()
64
  with gr.Row():
65
- image_out = gr.Image(visible=False)
66
  with gr.Column():
67
  task_name_radio = gr.Radio(choices = ["cat2dog", "dog2cat",], type="value", visible=False, label="Select a task that you want to accomplish") #, value="cat2dog"),
68
- btn_imageedit = gr.Button(value="Translate the image!",visible=False)
69
-
70
-
 
 
 
 
71
  btn_inversion.click(inversion,[image_in],[inversion_file, blip_prompt])
72
  btn_inversion.click(set_visible_true, [], task_name_radio) #inversion_file, blip_prompt,
73
  btn_inversion.click(set_visible_False, [], btn_inversion)
74
 
 
 
75
  task_name_radio.change(set_visible_true, [], btn_imageedit)
76
  task_name_radio.change(set_visible_true, [], image_out)
77
 
78
  btn_imageedit.click(image_edit,[task_name_radio],[image_out])
79
-
 
 
 
 
 
 
80
  image_in.clear(set_visible_true, [], btn_inversion)
81
  image_in.change(set_visible_true, [], btn_inversion)
82
  image_in.change(set_visible_true, [], blip_prompt)
 
27
  "--prompt", "output/test_cat/prompt/input_image.txt", "--task_name", task_name,
28
  "--results_folder", "output/test_cat/"])
29
  return "output/test_cat/edit/input_image.png"
30
+
31
+
32
+ #Similarly, we can edit the synthetic images generated by Stable Diffusion with the following command.
33
+ def synthetic_image_edit(prompt, task_name, progress=gr.Progress(track_tqdm=True)):
34
+ progress(0, desc="Starting...")
35
+ # Run the script file
36
+ subprocess.run(["python", "src/edit_synthetic.py", "--prompt_str", prompt,
37
+ "--task", task_name, "--results_folder", "output/synth_editing"])
38
+ return "output/synth_editing/reconstruction.png", "output/synth_editing/edit.png"
39
+
40
+
41
  def set_visible_true():
42
  return gr.update(visible=True)
43
 
 
64
  Please visit their website and <a href="https://github.com/pix2pixzero/pix2pix-zero" target="_blank">github repo</a> for more details.
65
  </p></div>""")
66
  with gr.Row():
67
+ image_in = gr.Image(type="pil", label="Upload the image of a cat or a dog you want to translate")
68
  with gr.Column():
69
+ btn_inversion = gr.Button("Get input noise",visible=False )
70
  with gr.Row():
71
  blip_prompt = gr.Textbox(visible=False)
72
  inversion_file = gr.File(visible=False)
73
  #task_name = gr.Textbox()
74
  with gr.Row():
75
+ image_out = gr.Image(visible=False, label="Trnaslated Image output")
76
  with gr.Column():
77
  task_name_radio = gr.Radio(choices = ["cat2dog", "dog2cat",], type="value", visible=False, label="Select a task that you want to accomplish") #, value="cat2dog"),
78
+ btn_imageedit = gr.Button(value="Edit the image!",visible=False)
79
+ prompt_synth = gr.Textbox(visible=False)
80
+ btn_synth_image = gr.Button(value="Generate & Translate SD image",visible=False)
81
+ with gr.Row():
82
+ image_synth = gr.Image(visible=False, label="Synthetic image generated by Stable Diffusion on the fly")
83
+ image_synth_translated = gr.Image(visible=False, label="Translated synthetic image")
84
+
85
  btn_inversion.click(inversion,[image_in],[inversion_file, blip_prompt])
86
  btn_inversion.click(set_visible_true, [], task_name_radio) #inversion_file, blip_prompt,
87
  btn_inversion.click(set_visible_False, [], btn_inversion)
88
 
89
+ #task_initial_radio.change(set_visible_true, [], btn_imageedit)
90
+
91
  task_name_radio.change(set_visible_true, [], btn_imageedit)
92
  task_name_radio.change(set_visible_true, [], image_out)
93
 
94
  btn_imageedit.click(image_edit,[task_name_radio],[image_out])
95
+ btn_imageedit.click(set_visible_False, [], btn_imageedit)
96
+ btn_imageedit.click(set_visible_true, [], prompt_synth)
97
+ btn_imageedit.click(set_visible_true, [], btn_synth_image)
98
+ btn_imageedit.click(set_visible_true, [], image_synth)
99
+ btn_imageedit.click(set_visible_true, [], image_synth_translated)
100
+ btn_synth_image.click(synthetic_image_edit,[prompt_synth, task_name_radio],[image_synth, image_synth_translated])
101
+
102
  image_in.clear(set_visible_true, [], btn_inversion)
103
  image_in.change(set_visible_true, [], btn_inversion)
104
  image_in.change(set_visible_true, [], blip_prompt)