Files changed (2) hide show
  1. README.md +2 -2
  2. app.py +41 -41
README.md CHANGED
@@ -4,11 +4,11 @@ emoji: 🔥
4
  colorFrom: yellow
5
  colorTo: gray
6
  sdk: gradio
7
- sdk_version: 4.44.1
8
  app_file: app.py
9
  pinned: true
10
  license: mit
11
  disable_embedding: true
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
4
  colorFrom: yellow
5
  colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 3.20.0
8
  app_file: app.py
9
  pinned: true
10
  license: mit
11
  disable_embedding: true
12
  ---
13
 
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -5,12 +5,10 @@ from PIL import Image
5
  import re
6
  import os
7
  import requests
8
- import uuid
9
- import base64
10
 
11
  from share_btn import community_icon_html, loading_icon_html, share_js
12
 
13
- word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt")
14
  word_list = word_list_dataset["train"]['text']
15
 
16
  is_gpu_busy = False
@@ -18,28 +16,20 @@ def infer(prompt, negative, scale):
18
  global is_gpu_busy
19
  for filter in word_list:
20
  if re.search(rf"\b{filter}\b", prompt):
21
- print(filter)
22
- print(prompt)
23
  raise gr.Error("Unsafe content found. Please try again with different prompts.")
24
 
25
  images = []
26
  url = os.getenv('JAX_BACKEND_URL')
27
- print(url)
28
  payload = {'prompt': prompt, 'negative_prompt': negative, 'guidance_scale': scale}
29
  images_request = requests.post(url, json = payload)
30
  for image in images_request.json()["images"]:
31
- file_path = f"{uuid.uuid4()}.jpg"
32
- with open(file_path, "wb") as f:
33
- f.write(base64.b64decode(image))
34
- images.append(file_path)
35
 
36
- return images
37
 
38
 
39
  css = """
40
- .gradio-container {
41
- max-width: 768px !important;
42
- }
43
  .gradio-container {
44
  font-family: 'IBM Plex Sans', sans-serif;
45
  }
@@ -57,6 +47,7 @@ css = """
57
  .container {
58
  max-width: 730px;
59
  margin: auto;
 
60
  }
61
  #gallery {
62
  min-height: 22rem;
@@ -137,9 +128,6 @@ css = """
137
  margin-top: 10px;
138
  margin-left: auto;
139
  }
140
- #share-btn-container .styler{
141
- background-color: #000000;
142
- }
143
  #share-btn {
144
  all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;right:0;
145
  }
@@ -163,7 +151,6 @@ css = """
163
  #prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
164
  #component-16{border-top-width: 1px!important;margin-top: 1em}
165
  .image_duplication{position: absolute; width: 100px; left: 50px}
166
- button{height: 100%}
167
  """
168
 
169
  block = gr.Blocks(css=css)
@@ -260,28 +247,40 @@ with block:
260
  """
261
  )
262
  with gr.Group():
263
- with gr.Row(elem_id="prompt-container"):
264
- with gr.Column(scale=3):
265
- text = gr.Textbox(
266
- label="Enter your prompt",
267
- show_label=False,
268
- max_lines=1,
269
- placeholder="Enter your prompt",
270
- elem_id="prompt-text-input",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  )
272
- negative = gr.Textbox(
273
- label="Enter your negative prompt",
274
- show_label=False,
275
- max_lines=1,
276
- placeholder="Enter a negative prompt",
277
- elem_id="negative-prompt-text-input",
278
- )
279
- with gr.Column(scale=1, min_width=150):
280
- btn = gr.Button("Generate image")
281
 
282
  gallery = gr.Gallery(
283
  label="Generated images", show_label=False, elem_id="gallery"
284
- )
285
 
286
  with gr.Group(elem_id="container-advanced-btns"):
287
  #advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
@@ -307,9 +306,9 @@ with block:
307
 
308
  ex = gr.Examples(examples=examples, fn=infer, inputs=[text, negative, guidance_scale], outputs=[gallery, community_icon, loading_icon, share_button], cache_examples=False)
309
  ex.dataset.headers = [""]
310
- negative.submit(infer, inputs=[text, negative, guidance_scale], outputs=[gallery], concurrency_limit=80)
311
- text.submit(infer, inputs=[text, negative, guidance_scale], outputs=[gallery], concurrency_limit=80)
312
- btn.click(infer, inputs=[text, negative, guidance_scale], outputs=[gallery], concurrency_limit=80)
313
 
314
  #advanced_button.click(
315
  # None,
@@ -325,7 +324,7 @@ with block:
325
  None,
326
  [],
327
  [],
328
- js=share_js,
329
  )
330
  gr.HTML(
331
  """
@@ -345,5 +344,6 @@ Despite how impressive being able to turn text into image is, beware to the fact
345
  </div>
346
  """
347
  )
 
348
 
349
- block.queue().launch(max_threads=150, show_error=True)
 
5
  import re
6
  import os
7
  import requests
 
 
8
 
9
  from share_btn import community_icon_html, loading_icon_html, share_js
10
 
11
+ word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)
12
  word_list = word_list_dataset["train"]['text']
13
 
14
  is_gpu_busy = False
 
16
  global is_gpu_busy
17
  for filter in word_list:
18
  if re.search(rf"\b{filter}\b", prompt):
 
 
19
  raise gr.Error("Unsafe content found. Please try again with different prompts.")
20
 
21
  images = []
22
  url = os.getenv('JAX_BACKEND_URL')
 
23
  payload = {'prompt': prompt, 'negative_prompt': negative, 'guidance_scale': scale}
24
  images_request = requests.post(url, json = payload)
25
  for image in images_request.json()["images"]:
26
+ image_b64 = (f"data:image/jpeg;base64,{image}")
27
+ images.append(image_b64)
 
 
28
 
29
+ return images
30
 
31
 
32
  css = """
 
 
 
33
  .gradio-container {
34
  font-family: 'IBM Plex Sans', sans-serif;
35
  }
 
47
  .container {
48
  max-width: 730px;
49
  margin: auto;
50
+ padding-top: 1.5rem;
51
  }
52
  #gallery {
53
  min-height: 22rem;
 
128
  margin-top: 10px;
129
  margin-left: auto;
130
  }
 
 
 
131
  #share-btn {
132
  all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;right:0;
133
  }
 
151
  #prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
152
  #component-16{border-top-width: 1px!important;margin-top: 1em}
153
  .image_duplication{position: absolute; width: 100px; left: 50px}
 
154
  """
155
 
156
  block = gr.Blocks(css=css)
 
247
  """
248
  )
249
  with gr.Group():
250
+ with gr.Box():
251
+ with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
252
+ with gr.Column():
253
+ text = gr.Textbox(
254
+ label="Enter your prompt",
255
+ show_label=False,
256
+ max_lines=1,
257
+ placeholder="Enter your prompt",
258
+ elem_id="prompt-text-input",
259
+ ).style(
260
+ border=(True, False, True, True),
261
+ rounded=(True, False, False, True),
262
+ container=False,
263
+ )
264
+ negative = gr.Textbox(
265
+ label="Enter your negative prompt",
266
+ show_label=False,
267
+ max_lines=1,
268
+ placeholder="Enter a negative prompt",
269
+ elem_id="negative-prompt-text-input",
270
+ ).style(
271
+ border=(True, False, True, True),
272
+ rounded=(True, False, False, True),
273
+ container=False,
274
+ )
275
+ btn = gr.Button("Generate image").style(
276
+ margin=False,
277
+ rounded=(False, True, True, False),
278
+ full_width=False,
279
  )
 
 
 
 
 
 
 
 
 
280
 
281
  gallery = gr.Gallery(
282
  label="Generated images", show_label=False, elem_id="gallery"
283
+ ).style(grid=[2], height="auto")
284
 
285
  with gr.Group(elem_id="container-advanced-btns"):
286
  #advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
 
306
 
307
  ex = gr.Examples(examples=examples, fn=infer, inputs=[text, negative, guidance_scale], outputs=[gallery, community_icon, loading_icon, share_button], cache_examples=False)
308
  ex.dataset.headers = [""]
309
+ negative.submit(infer, inputs=[text, negative, guidance_scale], outputs=[gallery], postprocess=False)
310
+ text.submit(infer, inputs=[text, negative, guidance_scale], outputs=[gallery], postprocess=False)
311
+ btn.click(infer, inputs=[text, negative, guidance_scale], outputs=[gallery], postprocess=False)
312
 
313
  #advanced_button.click(
314
  # None,
 
324
  None,
325
  [],
326
  [],
327
+ _js=share_js,
328
  )
329
  gr.HTML(
330
  """
 
344
  </div>
345
  """
346
  )
347
+
348
 
349
+ block.queue(concurrency_count=80, max_size=100).launch(max_threads=150)