kadirnar commited on
Commit
b3140ad
1 Parent(s): 236d2b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +150 -129
app.py CHANGED
@@ -160,141 +160,162 @@ with gr.Blocks(css=css) as demo:
160
  </h3>
161
  """
162
  )
163
- with gr.Group():
164
- with gr.Row():
165
- prompt = gr.Text(
166
- label="Prompt",
167
- show_label=False,
168
- max_lines=1,
169
- placeholder="Enter your prompt",
170
- container=False,
171
- )
172
- run_button = gr.Button("Run", scale=0)
173
- result = gr.Gallery(label="Result", elem_id="gallery", show_label=False)
174
- with gr.Accordion("Advanced options", open=False):
175
- with gr.Row():
176
- use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
177
- negative_prompt = gr.Text(
178
- label="Negative prompt",
179
- max_lines=1,
180
- value = "deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
181
- visible=True,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  )
183
- seed = gr.Slider(
184
- label="Seed",
185
- minimum=0,
186
- maximum=MAX_SEED,
187
- step=1,
188
- value=0,
189
- )
190
 
191
- steps = gr.Slider(
192
- label="Steps",
193
- minimum=0,
194
- maximum=60,
195
- step=1,
196
- value=25,
197
- )
198
- number_image = gr.Slider(
199
- label="Number of Images",
200
- minimum=1,
201
- maximum=4,
202
- step=1,
203
- value=1,
204
- )
205
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
206
- with gr.Row(visible=True):
207
- width = gr.Slider(
208
- label="Width",
209
- minimum=256,
210
- maximum=MAX_IMAGE_SIZE,
211
- step=32,
212
- value=1024,
213
  )
214
- height = gr.Slider(
215
- label="Height",
216
- minimum=256,
217
- maximum=MAX_IMAGE_SIZE,
218
- step=32,
219
- value=1024,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  )
221
- with gr.Row():
222
- guidance_scale = gr.Slider(
223
- label="Guidance Scale",
224
- minimum=0.1,
225
- maximum=10,
226
- step=0.1,
227
- value=7.0,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  )
229
-
230
  with gr.Group():
231
- with gr.Row():
232
- with gr.Column():
233
- init_image = gr.Image(label="Input Image", type="pil")
234
- with gr.Column():
235
- img2img_output = gr.Gallery(label="Result", elem_id="gallery", show_label=False)
236
- strength = gr.Slider(label="Img2Img Strength", minimum=0.0, maximum=1.0, step=0.01, value=0.8)
237
-
238
- gr.Examples(
239
- examples=examples,
240
- inputs=prompt,
241
- outputs=[result],
242
- fn=generate,
243
- cache_examples=CACHE_EXAMPLES,
244
- )
245
-
246
- use_negative_prompt.change(
247
- fn=lambda x: gr.update(visible=x),
248
- inputs=use_negative_prompt,
249
- outputs=negative_prompt,
250
- api_name=False,
251
- )
252
-
253
- gr.on(
254
- triggers=[
255
- prompt.submit,
256
- negative_prompt.submit,
257
- run_button.click,
258
- ],
259
- fn=generate,
260
- inputs=[
261
- prompt,
262
- negative_prompt,
263
- use_negative_prompt,
264
- seed,
265
- width,
266
- height,
267
- guidance_scale,
268
- randomize_seed,
269
- steps,
270
- number_image,
271
- ],
272
- outputs=[result],
273
- api_name="run",
274
- )
275
-
276
- gr.on(
277
- triggers=[
278
- prompt.submit,
279
- negative_prompt.submit,
280
- run_button.click,
281
- ],
282
- fn=img2img_generate,
283
- inputs=[
284
- prompt,
285
- init_image,
286
- negative_prompt,
287
- use_negative_prompt,
288
- seed,
289
- guidance_scale,
290
- randomize_seed,
291
- steps,
292
- strength,
293
- number_image,
294
- ],
295
- outputs=[img2img_output],
296
- api_name="img2img_run",
297
- )
298
 
299
  if __name__ == "__main__":
300
  demo.queue().launch()
 
160
  </h3>
161
  """
162
  )
163
+
164
+ with gr.Tabs():
165
+ with gr.TabItem("Text to Image"):
166
+ with gr.Group():
167
+ with gr.Row():
168
+ prompt = gr.Text(
169
+ label="Prompt",
170
+ show_label=False,
171
+ max_lines=1,
172
+ placeholder="Enter your prompt",
173
+ container=False,
174
+ )
175
+ run_button = gr.Button("Run", scale=0)
176
+ result = gr.Gallery(label="Result", elem_id="gallery", show_label=False)
177
+ with gr.Accordion("Advanced options", open=False):
178
+ with gr.Row():
179
+ use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
180
+ negative_prompt = gr.Text(
181
+ label="Negative prompt",
182
+ max_lines=1,
183
+ value = "deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
184
+ visible=True,
185
+ )
186
+ seed = gr.Slider(
187
+ label="Seed",
188
+ min=0,
189
+ maximum=MAX_SEED,
190
+ step=1,
191
+ value=0,
192
+ )
193
+
194
+ steps = gr.Slider(
195
+ label="Steps",
196
+ min=0,
197
+ maximum=60,
198
+ step=1,
199
+ value=25,
200
+ )
201
+ number_image = gr.Slider(
202
+ label="Number of Images",
203
+ min=1,
204
+ maximum=4,
205
+ step=1,
206
+ value=1,
207
+ )
208
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
209
+ with gr.Row(visible=True):
210
+ width = gr.Slider(
211
+ label="Width",
212
+ min=256,
213
+ maximum=MAX_IMAGE_SIZE,
214
+ step=32,
215
+ value=1024,
216
+ )
217
+ height = gr.Slider(
218
+ label="Height",
219
+ minimum=256,
220
+ maximum=MAX_IMAGE_SIZE,
221
+ step=32,
222
+ value=1024,
223
+ )
224
+ with gr.Row():
225
+ guidance_scale = gr.Slider(
226
+ label="Guidance Scale",
227
+ min=0.1,
228
+ maximum=10,
229
+ step=0.1,
230
+ value=7.0,
231
+ )
232
+
233
+ gr.Examples(
234
+ examples=examples,
235
+ inputs=prompt,
236
+ outputs=[result],
237
+ fn=generate,
238
+ cache_examples=CACHE_EXAMPLES,
239
  )
 
 
 
 
 
 
 
240
 
241
+ use_negative_prompt.change(
242
+ fn=lambda x: gr.update(visible=x),
243
+ inputs=use_negative_prompt,
244
+ outputs=negative_prompt,
245
+ api_name=False,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  )
247
+
248
+ gr.on(
249
+ triggers=[
250
+ prompt.submit,
251
+ negative_prompt.submit,
252
+ run_button.click,
253
+ ],
254
+ fn=generate,
255
+ inputs=[
256
+ prompt,
257
+ negative_prompt,
258
+ use_negative_prompt,
259
+ seed,
260
+ width,
261
+ height,
262
+ guidance_scale,
263
+ randomize_seed,
264
+ steps,
265
+ number_image,
266
+ ],
267
+ outputs=[result],
268
+ api_name="run",
269
  )
270
+
271
+ with gr.TabItem("Image to Image"):
272
+ with gr.Group():
273
+ with gr.Row():
274
+ with gr.Column():
275
+ init_image = gr.Image(label="Input Image", type="pil")
276
+ with gr.Column():
277
+ img2img_output = gr.Gallery(label="Result", elem_id="gallery", show_label=False)
278
+ strength = gr.Slider(label="Img2Img Strength", minimum=0.0, maximum=1.0, step=0.01, value=0.8)
279
+
280
+ gr.on(
281
+ triggers=[
282
+ prompt.submit,
283
+ negative_prompt.submit,
284
+ run_button.click,
285
+ ],
286
+ fn=img2img_generate,
287
+ inputs=[
288
+ prompt,
289
+ init_image,
290
+ negative_prompt,
291
+ use_negative_prompt,
292
+ seed,
293
+ guidance_scale,
294
+ randomize_seed,
295
+ steps,
296
+ strength,
297
+ number_image,
298
+ ],
299
+ outputs=[img2img_output],
300
+ api_name="img2img_run",
301
  )
302
+
303
  with gr.Group():
304
+ gr.HTML(
305
+ """
306
+ <p style='text-align: center'>
307
+ Generated results will be displayed here.
308
+ </p>
309
+ """
310
+ )
311
+ generated_table = gr.Table(
312
+ headers=["Prompt", "Seed", "Image"],
313
+ row_count=1,
314
+ col_count=(3, "fixed"),
315
+ type="gallery",
316
+ show_label=False,
317
+ elem_id="generated-table",
318
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
 
320
  if __name__ == "__main__":
321
  demo.queue().launch()