Linoy Tsaban commited on
Commit
536c8d2
1 Parent(s): fbcd65a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -33
app.py CHANGED
@@ -70,36 +70,8 @@ def get_example():
70
  return case
71
 
72
 
73
- def edit(input_image,
74
- src_prompt ="",
75
- tar_prompt="",
76
- steps=100,
77
- cfg_scale_src = 3.5,
78
- cfg_scale_tar = 15,
79
- skip=36,
80
- seed = 0,
81
- wt = None,
82
- zs = None,
83
- wts = None
84
-
85
- ):
86
- torch.manual_seed(seed)
87
- # offsets=(0,0,0,0)
88
- x0 = load_512(input_image, device=device)
89
 
90
- if not wt:
91
- # invert and retrieve noise maps and latent
92
- wt, zs, wts = invert(x0 =x0 , prompt_src=src_prompt, num_diffusion_steps=steps, cfg_scale_src=cfg_scale_src)
93
-
94
- output = sample(wt, zs, wts, prompt_tar=tar_prompt, cfg_scale_tar=cfg_scale_tar, skip=skip)
95
 
96
- return output
97
-
98
-
99
- def reset_latents():
100
- wt = gr.State(value=None)
101
- zs = gr.State(value=None)
102
- wts = gr.State(value=None)
103
 
104
 
105
 
@@ -121,6 +93,35 @@ For faster inference without waiting in queue, you may duplicate the space and u
121
  <img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
122
  <p/>"""
123
  with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  gr.HTML(intro)
125
  wt = gr.State(value=None)
126
  zs = gr.State(value=None)
@@ -184,17 +185,14 @@ with gr.Blocks() as demo:
184
  edit_button.click(
185
  fn=edit,
186
  inputs=[input_image,
 
187
  src_prompt,
188
  tar_prompt,
189
  steps,
190
  cfg_scale_src,
191
  cfg_scale_tar,
192
  skip,
193
- seed,
194
- wt,
195
- zs,
196
- wts
197
-
198
  ],
199
  outputs=[output_image],
200
  )
@@ -203,6 +201,10 @@ with gr.Blocks() as demo:
203
  fn = reset_latents
204
  )
205
 
 
 
 
 
206
 
207
  gr.Examples(
208
  label='Examples',
 
70
  return case
71
 
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
 
 
 
 
 
74
 
 
 
 
 
 
 
 
75
 
76
 
77
 
 
93
  <img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
94
  <p/>"""
95
  with gr.Blocks() as demo:
96
+
97
+ def reset_latents():
98
+ wt = gr.State(value=None)
99
+ zs = gr.State(value=None)
100
+ wts = gr.State(value=None)
101
+
102
+ def edit(input_image,
103
+ wt, zs, wts,
104
+ src_prompt ="",
105
+ tar_prompt="",
106
+ steps=100,
107
+ cfg_scale_src = 3.5,
108
+ cfg_scale_tar = 15,
109
+ skip=36,
110
+ seed = 0,
111
+
112
+ ):
113
+ torch.manual_seed(seed)
114
+ # offsets=(0,0,0,0)
115
+ x0 = load_512(input_image, device=device)
116
+
117
+ if not wt:
118
+ # invert and retrieve noise maps and latent
119
+ wt, zs, wts = invert(x0 =x0 , prompt_src=src_prompt, num_diffusion_steps=steps, cfg_scale_src=cfg_scale_src)
120
+
121
+ output = sample(wt, zs, wts, prompt_tar=tar_prompt, cfg_scale_tar=cfg_scale_tar, skip=skip)
122
+
123
+ return output
124
+
125
  gr.HTML(intro)
126
  wt = gr.State(value=None)
127
  zs = gr.State(value=None)
 
185
  edit_button.click(
186
  fn=edit,
187
  inputs=[input_image,
188
+ wt, zs, wts,
189
  src_prompt,
190
  tar_prompt,
191
  steps,
192
  cfg_scale_src,
193
  cfg_scale_tar,
194
  skip,
195
+ seed
 
 
 
 
196
  ],
197
  outputs=[output_image],
198
  )
 
201
  fn = reset_latents
202
  )
203
 
204
+ src_prompt.change(
205
+ fn = reset_latents
206
+ )
207
+
208
 
209
  gr.Examples(
210
  label='Examples',