superlazycoder commited on
Commit
695c5a0
·
verified ·
1 Parent(s): 23351b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py CHANGED
@@ -34,6 +34,32 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
34
 
35
  return image
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  examples = [
38
  "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
39
  "An astronaut riding a green horse",
@@ -69,6 +95,9 @@ with gr.Blocks(css=css) as demo:
69
  )
70
 
71
  run_button = gr.Button("Run", scale=0)
 
 
 
72
 
73
  result = gr.Image(label="Result", show_label=False)
74
 
@@ -138,4 +167,16 @@ with gr.Blocks(css=css) as demo:
138
  outputs = [result]
139
  )
140
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  demo.queue().launch()
 
34
 
35
  return image
36
 
37
+
38
+
39
+ @spaces.GPU
40
+ def reject(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
41
+
42
+ if randomize_seed:
43
+ seed = random.randint(0, MAX_SEED)
44
+
45
+ generator = torch.Generator().manual_seed(seed)
46
+
47
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
48
+ pipe.enable_xformers_memory_efficient_attention()
49
+ pipe = pipe.to(device)
50
+
51
+ image = pipe(
52
+ prompt = prompt,
53
+ negative_prompt = negative_prompt,
54
+ guidance_scale = guidance_scale,
55
+ num_inference_steps = num_inference_steps,
56
+ width = width,
57
+ height = height,
58
+ generator = generator
59
+ ).images[0]
60
+
61
+ return image
62
+
63
  examples = [
64
  "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
65
  "An astronaut riding a green horse",
 
95
  )
96
 
97
  run_button = gr.Button("Run", scale=0)
98
+
99
+ left_button = gr.Button("Left", scale=0)
100
+ right_button = gr.Button("Right", scale=0)
101
 
102
  result = gr.Image(label="Result", show_label=False)
103
 
 
167
  outputs = [result]
168
  )
169
 
170
+ left_button.click(
171
+ fn = reject,
172
+ inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
173
+ outputs = [result]
174
+ )
175
+
176
+ right_button.click(
177
+ fn = reject,
178
+ inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
179
+ outputs = [result]
180
+ )
181
+
182
  demo.queue().launch()