ash123 commited on
Commit
72d3b5f
1 Parent(s): 0905ea0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -55
app.py CHANGED
@@ -51,7 +51,6 @@ def generate_image(prompt: str, negative_prompt: str = "", inference_steps: int
51
  images = pipeline.numpy_to_pil(images)
52
  return images[0]
53
 
54
-
55
  examples = [
56
  ["A watercolor painting of a bird"],
57
  ["A watercolor painting of an otter"]
@@ -59,6 +58,9 @@ examples = [
59
  css = """
60
  .gradio-container {
61
  font-family: 'IBM Plex Sans', sans-serif;
 
 
 
62
  }
63
  .gr-button {
64
  color: white;
@@ -154,7 +156,7 @@ css = """
154
  display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
155
  margin-top: 10px;
156
  margin-left: auto;
157
- }
158
  #share-btn {
159
  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;
160
  }
@@ -168,16 +170,18 @@ css = """
168
  #share-btn-container .wrap {
169
  display: none !important;
170
  }
171
-
 
 
172
  .gr-form{
173
  flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
174
  }
175
  #prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
176
- #component-16{border-top-width: 1px!important;margin-top: 1em}
177
  .image_duplication{position: absolute; width: 100px; left: 50px}
 
178
  """
179
 
180
- block = gr.Blocks(css=css)
181
 
182
  with block as demo:
183
  gr.HTML(
@@ -237,64 +241,51 @@ with block as demo:
237
  with gr.Group():
238
  with gr.Box():
239
  with gr.Row(elem_id="prompt-container").style(equal_height=True):
240
- with gr.Column():
241
  prompt_input = gr.Textbox(
242
  label="Enter your prompt",
243
  max_lines=1,
244
- placeholder="A watercolor painting of a bird",
245
  elem_id="prompt-text-input",
246
- ).style(
247
- border=(True, False, True, True),
248
- rounded=(True, False, False, True),
249
- container=False,
250
  )
251
  negative = gr.Textbox(
252
  label="Enter your negative prompt",
253
  max_lines=1,
254
- placeholder="tree",
255
  elem_id="negative-prompt-text-input",
256
- ).style(
257
- border=(True, False, True, True),
258
- rounded=(True, False, False, True),
259
- container=False,
260
  )
261
- btn = gr.Button("Generate image").style(
262
- margin=False,
263
- rounded=(False, True, True, False),
264
- full_width=False,
265
- )
266
 
267
  gallery = gr.Gallery(
268
  label="Generated images", show_label=False, elem_id="gallery"
269
  ).style(grid=[2], height="auto")
270
 
271
- with gr.Group(elem_id="container-advanced-btns"):
272
- # advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
273
- with gr.Group(elem_id="share-btn-container"):
274
- community_icon = gr.HTML(community_icon_html)
275
- loading_icon = gr.HTML(loading_icon_html)
276
- share_button = gr.Button(
277
- "Share to community", elem_id="share-btn")
278
 
279
- with gr.Accordion("Advanced settings", open=False):
280
- # gr.Markdown("Advanced settings are temporarily unavailable")
281
- # samples = gr.Slider(label="Images", minimum=1, maximum=4, value=4, step=1)
282
- # steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=45, step=1)
283
- inf_steps_input = gr.inputs.Slider(
284
- minimum=1, maximum=100, default=25, step=1, label="Inference Steps"
285
- )
286
- seed_input = gr.inputs.Number(default=0, label="Seed")
287
- guidance_scale = gr.Slider(
288
- label="Guidance Scale", minimum=0, maximum=50, value=9, step=0.1
289
- )
 
 
 
 
 
 
 
 
 
 
 
290
 
291
- ex = gr.Examples(examples=examples,
292
- fn=generate_image,
293
- inputs=[prompt_input, negative,
294
- inf_steps_input, seed_input, guidance_scale],
295
- outputs=[gallery],
296
- cache_examples=True)
297
- ex.dataset.headers = [""]
298
  negative.submit(generate_image, inputs=[
299
  prompt_input, negative, inf_steps_input, seed_input, guidance_scale], outputs=[gallery], postprocess=False)
300
  prompt_input.submit(generate_image, inputs=[
@@ -308,14 +299,7 @@ with block as demo:
308
  [],
309
  _js=share_js,
310
  )
311
- gr.HTML(
312
- """
313
- <div class="footer">
314
- <p>Model by Stable Diffusion Nano Team
315
- </p>
316
- </div>
317
- """
318
- )
319
  with gr.Accordion(label="License", open=False):
320
  gr.HTML(
321
  """
@@ -323,9 +307,10 @@ with block as demo:
323
  <p><h4>LICENSE</h4>
324
  The model is licensed with a <a href="https://huggingface.co/stabilityai/stable-diffusion-2/blob/main/LICENSE-MODEL" style="text-decoration: underline;" target="_blank">CreativeML OpenRAIL++</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p>
325
  <p><h4>Biases and content acknowledgment</h4>
326
- Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" style="text-decoration: underline;" target="_blank">model card</a></p>
327
  </div>
328
  """
329
  )
330
  demo.queue(concurrency_count=10)
331
  demo.launch()
 
 
51
  images = pipeline.numpy_to_pil(images)
52
  return images[0]
53
 
 
54
  examples = [
55
  ["A watercolor painting of a bird"],
56
  ["A watercolor painting of an otter"]
 
58
  css = """
59
  .gradio-container {
60
  font-family: 'IBM Plex Sans', sans-serif;
61
+ max-width: 730px!important;
62
+ margin: auto;
63
+ padding-top: 1.5rem;
64
  }
65
  .gr-button {
66
  color: white;
 
156
  display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
157
  margin-top: 10px;
158
  margin-left: auto;
159
+
160
  #share-btn {
161
  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;
162
  }
 
170
  #share-btn-container .wrap {
171
  display: none !important;
172
  }
173
+ .share_button {
174
+ color:#6366f1!important;
175
+ }
176
  .gr-form{
177
  flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
178
  }
179
  #prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
 
180
  .image_duplication{position: absolute; width: 100px; left: 50px}
181
+
182
  """
183
 
184
+ block = gr.Blocks(theme="gradio/soft",css=css)
185
 
186
  with block as demo:
187
  gr.HTML(
 
241
  with gr.Group():
242
  with gr.Box():
243
  with gr.Row(elem_id="prompt-container").style(equal_height=True):
244
+ with gr.Column(scale=2):
245
  prompt_input = gr.Textbox(
246
  label="Enter your prompt",
247
  max_lines=1,
248
+ placeholder="Enter your prompt",
249
  elem_id="prompt-text-input",
250
+ show_label=False,
 
 
 
251
  )
252
  negative = gr.Textbox(
253
  label="Enter your negative prompt",
254
  max_lines=1,
255
+ placeholder="Enter a negative prompt",
256
  elem_id="negative-prompt-text-input",
257
+ show_label=False,
 
 
 
258
  )
259
+ btn = gr.Button("Generate image", label="Primary Button", variant="primary")
 
 
 
 
260
 
261
  gallery = gr.Gallery(
262
  label="Generated images", show_label=False, elem_id="gallery"
263
  ).style(grid=[2], height="auto")
264
 
 
 
 
 
 
 
 
265
 
266
+ with gr.Row():
267
+ with gr.Column(scale=2):
268
+ with gr.Accordion("Advanced settings"):
269
+ seed_input = gr.inputs.Number(default=0, label="Seed")
270
+ inf_steps_input = gr.inputs.Slider(
271
+ minimum=1, maximum=100, default=25, step=1, label="Inference Steps"
272
+ )
273
+ guidance_scale = gr.inputs.Slider(
274
+ label="Guidance Scale", minimum=0, maximum=50, default=9, step=0.1
275
+ )
276
+ with gr.Column(scale=1):
277
+ # advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
278
+ ex = gr.Examples(examples=examples,
279
+ fn=generate_image,
280
+ inputs=[prompt_input, negative,
281
+ inf_steps_input, seed_input, guidance_scale],
282
+ outputs=[gallery],
283
+ cache_examples=False)
284
+ ex.dataset.headers = [""]
285
+
286
+ share_button = gr.Button("Share to community",elem_classes="share_button")
287
+
288
 
 
 
 
 
 
 
 
289
  negative.submit(generate_image, inputs=[
290
  prompt_input, negative, inf_steps_input, seed_input, guidance_scale], outputs=[gallery], postprocess=False)
291
  prompt_input.submit(generate_image, inputs=[
 
299
  [],
300
  _js=share_js,
301
  )
302
+ gr.Markdown("Model by Stable Diffusion Nano Team",elem_classes="footer")
 
 
 
 
 
 
 
303
  with gr.Accordion(label="License", open=False):
304
  gr.HTML(
305
  """
 
307
  <p><h4>LICENSE</h4>
308
  The model is licensed with a <a href="https://huggingface.co/stabilityai/stable-diffusion-2/blob/main/LICENSE-MODEL" style="text-decoration: underline;" target="_blank">CreativeML OpenRAIL++</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p>
309
  <p><h4>Biases and content acknowledgment</h4>
310
+ Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://huggingface.co/datasets/laion/laion2B-en-aesthetic" style="text-decoration: underline;" target="_blank">LAION-2B Aesthetic dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/bguisard/stable-diffusion-nano-2-1" style="text-decoration: underline;" target="_blank">model card</a></p>
311
  </div>
312
  """
313
  )
314
  demo.queue(concurrency_count=10)
315
  demo.launch()
316
+