alvanlii commited on
Commit
d9210b8
1 Parent(s): 57b5308

Add load example button

Browse files
Files changed (1) hide show
  1. app.py +35 -15
app.py CHANGED
@@ -16,6 +16,29 @@ help_text = """"""
16
  def main():
17
  segmodel, model, diffusion, ldm, bert, clip_model, model_params = make_models()
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def generate(
20
  input_image: Image.Image,
21
  from_text: str,
@@ -44,7 +67,7 @@ def main():
44
 
45
  def reset():
46
  return [
47
- "Randomize Seed", 1371, None, 5.0,
48
  150, 16, 10000
49
  ]
50
 
@@ -57,8 +80,8 @@ def main():
57
  with gr.Row():
58
  with gr.Column(scale=1, min_width=100):
59
  generate_button = gr.Button("Generate")
60
- # with gr.Column(scale=1, min_width=100):
61
- # load_button = gr.Button("Load Example")
62
  with gr.Column(scale=1, min_width=100):
63
  reset_button = gr.Button("Reset")
64
  with gr.Column(scale=3):
@@ -96,20 +119,17 @@ def main():
96
 
97
  generate_button.click(
98
  fn=generate,
99
- inputs=[
100
- input_image,
101
- from_text,
102
- instruction,
103
- negative_prompt,
104
- randomize_seed,
105
- seed,
106
- guidance_scale,
107
- clip_guidance_scale,
108
- cutn,
109
- l2_sim_lambda
110
- ],
111
  outputs=[seed, edited_image_1],
112
  )
 
 
 
 
 
 
 
 
113
  reset_button.click(
114
  fn=reset,
115
  inputs=[],
 
16
  def main():
17
  segmodel, model, diffusion, ldm, bert, clip_model, model_params = make_models()
18
 
19
+ def load_sample():
20
+ SAMPLE_IMAGE = "./sample/flower1.jpg"
21
+ input_image = Image.open(SAMPLE_IMAGE)
22
+ from_text = "a flower"
23
+ instruction = "a sunflower"
24
+ negative_prompt = ""
25
+ seed = 42
26
+ guidance_scale = 5.0
27
+ clip_guidance_scale = 150
28
+ cutn = 16
29
+ l2_sim_lambda = 10_000
30
+
31
+ edited_image_1 = run_model(
32
+ segmodel, model, diffusion, ldm, bert, clip_model, model_params,
33
+ from_text, instruction, negative_prompt, input_image.convert('RGB'), seed, guidance_scale, clip_guidance_scale, cutn, l2_sim_lambda
34
+ )
35
+
36
+ return [
37
+ input_image, from_text, instruction, negative_prompt, seed, guidance_scale,
38
+ clip_guidance_scale, cutn, l2_sim_lambda, edited_image_1
39
+ ]
40
+
41
+
42
  def generate(
43
  input_image: Image.Image,
44
  from_text: str,
 
67
 
68
  def reset():
69
  return [
70
+ "Randomize Seed", 42, None, 5.0,
71
  150, 16, 10000
72
  ]
73
 
 
80
  with gr.Row():
81
  with gr.Column(scale=1, min_width=100):
82
  generate_button = gr.Button("Generate")
83
+ with gr.Column(scale=1, min_width=100):
84
+ load_button = gr.Button("Load Example")
85
  with gr.Column(scale=1, min_width=100):
86
  reset_button = gr.Button("Reset")
87
  with gr.Column(scale=3):
 
119
 
120
  generate_button.click(
121
  fn=generate,
122
+ inputs=[],
 
 
 
 
 
 
 
 
 
 
 
123
  outputs=[seed, edited_image_1],
124
  )
125
+
126
+ load_button.click(
127
+ fn=load_sample,
128
+ inputs=[],
129
+ outputs=[input_image, from_text, instruction, negative_prompt, seed, guidance_scale, clip_guidance_scale, cutn, l2_sim_lambda, edited_image_1],
130
+ )
131
+
132
+
133
  reset_button.click(
134
  fn=reset,
135
  inputs=[],