Spaces:
Running on CPU Upgrade

osanseviero pngwn HF staff commited on
Commit
b610311
β€’
1 Parent(s): 764ef5f

update gradio to v4 (#1915)

Browse files

- update gradio to v4 (90af988b50d7316c1e34de69c8da098a8321e9a0)
- Update README.md (b4f1d22b7e41c0f9f2d3159c80bd3deee7b775ce)


Co-authored-by: Pete <pngwn@users.noreply.huggingface.co>

Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +59 -45
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: πŸ‹οΈ #πŸ‘•πŸŒŸ
4
  colorFrom: red
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: 3.45.1
8
  app_file: app.py
9
  license: mit
10
  disable_embedding: true
 
4
  colorFrom: red
5
  colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 4.36.0
8
  app_file: app.py
9
  license: mit
10
  disable_embedding: true
app.py CHANGED
@@ -84,7 +84,14 @@ word_list = word_list_dataset["train"]['text']
84
 
85
  #gradio.helpers.CACHED_FOLDER="/data/cache"
86
 
87
- def infer(prompt, negative="low_quality", scale=7, style_name=None, profile: gr.OAuthProfile | None = None):
 
 
 
 
 
 
 
88
  for filter in word_list:
89
  if re.search(rf"\b{filter}\b", prompt):
90
  raise gr.Error("Please try again with a different prompt")
@@ -249,32 +256,11 @@ css = """
249
  block = gr.Blocks()
250
 
251
  examples = [
252
- [
253
- "A serious capybara at work, wearing a suit",
254
- None,
255
- None
256
- ],
257
- [
258
- 'A Squirtle fine dining with a view to the London Eye',
259
- None,
260
- None
261
- ],
262
- [
263
- 'A tamale food cart in front of a Japanese Castle',
264
- None,
265
- None
266
- ],
267
- [
268
- 'a graffiti of a robot serving meals to people',
269
- None,
270
- None
271
- ],
272
- [
273
- 'a beautiful cabin in Attersee, Austria, 3d animation style',
274
- None,
275
- None
276
- ],
277
-
278
  ]
279
 
280
 
@@ -333,19 +319,19 @@ with block:
333
  </div>
334
  """
335
  )
336
-
337
- with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
338
- text = gr.Textbox(
339
- label="Enter your prompt",
340
- show_label=False,
341
- max_lines=1,
342
- placeholder="Enter your prompt",
343
- elem_id="prompt-text-input",
344
- )
345
- btn = gr.Button("Generate", scale=0, elem_id="gen-button")
346
 
347
  gallery = gr.Gallery(
348
- label="Generated images", show_label=False, elem_id="gallery", grid=[2]
349
  )
350
 
351
 
@@ -372,16 +358,44 @@ with block:
372
  label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
373
  )
374
 
375
- ex = gr.Examples(examples=examples, fn=infer, inputs=[text, negative, guidance_scale], outputs=[gallery, community_group], cache_examples=True, postprocess=False)
376
- negative.submit(infer, inputs=[text, negative, guidance_scale, style_selection], outputs=[gallery, community_group], postprocess=False)
377
- text.submit(infer, inputs=[text, negative, guidance_scale, style_selection], outputs=[gallery, community_group], postprocess=False)
378
- btn.click(infer, inputs=[text, negative, guidance_scale, style_selection], outputs=[gallery, community_group], postprocess=False)
379
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  share_button.click(
381
  None,
382
  [],
383
  [],
384
- _js=share_js,
385
  )
386
  gr.HTML(
387
  """
@@ -408,5 +422,5 @@ with gr.Blocks(css=css) as block_with_history:
408
  with gr.Tab("Past generations"):
409
  user_history.render()
410
 
411
- block_with_history.queue(concurrency_count=8, max_size=10, api_open=False).launch(show_api=False)
412
  #block_with_history.launch(server_name="0.0.0.0")
 
84
 
85
  #gradio.helpers.CACHED_FOLDER="/data/cache"
86
 
87
+
88
+ def infer(
89
+ prompt,
90
+ negative="low_quality",
91
+ scale=7,
92
+ style_name=None,
93
+ profile: gr.OAuthProfile | None = None,
94
+ ):
95
  for filter in word_list:
96
  if re.search(rf"\b{filter}\b", prompt):
97
  raise gr.Error("Please try again with a different prompt")
 
256
  block = gr.Blocks()
257
 
258
  examples = [
259
+ ["A serious capybara at work, wearing a suit", "low_quality", 7],
260
+ ["A Squirtle fine dining with a view to the London Eye", "low_quality", 7],
261
+ ["A tamale food cart in front of a Japanese Castle", "low_quality", 7],
262
+ ["a graffiti of a robot serving meals to people", "low_quality", 7],
263
+ ["a beautiful cabin in Attersee, Austria, 3d animation style", "low_quality", 7],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  ]
265
 
266
 
 
319
  </div>
320
  """
321
  )
322
+
323
+ with gr.Row(elem_id="prompt-container", equal_height=True):
324
+ text = gr.Textbox(
325
+ label="Enter your prompt",
326
+ show_label=False,
327
+ max_lines=1,
328
+ placeholder="Enter your prompt",
329
+ elem_id="prompt-text-input",
330
+ )
331
+ btn = gr.Button("Generate", scale=0, elem_id="gen-button")
332
 
333
  gallery = gr.Gallery(
334
+ label="Generated images", show_label=False, elem_id="gallery", rows=2, columns=2
335
  )
336
 
337
 
 
358
  label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
359
  )
360
 
361
+ ex = gr.Examples(
362
+ examples=examples,
363
+ fn=infer,
364
+ inputs=[text, negative, guidance_scale],
365
+ outputs=[gallery, community_group],
366
+ cache_examples=True,
367
+ postprocess=False,
368
+ )
369
+ negative.submit(
370
+ infer,
371
+ inputs=[text, negative, guidance_scale, style_selection],
372
+ outputs=[gallery, community_group],
373
+ postprocess=False,
374
+ concurrency_id="infer",
375
+ concurrency_limit=8,
376
+ )
377
+ text.submit(
378
+ infer,
379
+ inputs=[text, negative, guidance_scale, style_selection],
380
+ outputs=[gallery, community_group],
381
+ postprocess=False,
382
+ concurrency_id="infer",
383
+ concurrency_limit=8,
384
+ )
385
+ btn.click(
386
+ infer,
387
+ inputs=[text, negative, guidance_scale, style_selection],
388
+ outputs=[gallery, community_group],
389
+ postprocess=False,
390
+ concurrency_id="infer",
391
+ concurrency_limit=8,
392
+ )
393
+
394
  share_button.click(
395
  None,
396
  [],
397
  [],
398
+ js=share_js,
399
  )
400
  gr.HTML(
401
  """
 
422
  with gr.Tab("Past generations"):
423
  user_history.render()
424
 
425
+ block_with_history.queue(max_size=10, api_open=False).launch(show_api=False)
426
  #block_with_history.launch(server_name="0.0.0.0")