prithivMLmods commited on
Commit
c9fdc92
1 Parent(s): 70d9d18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -34
app.py CHANGED
@@ -7,10 +7,9 @@ import uuid
7
  import gradio as gr
8
  import numpy as np
9
  from PIL import Image
10
- import spaces
11
- from typing import Tuple
12
  import torch
13
  from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
 
14
 
15
  DESCRIPTION = """ """
16
 
@@ -29,8 +28,6 @@ MAX_SEED = np.iinfo(np.int32).max
29
  if not torch.cuda.is_available():
30
  DESCRIPTION += "\n<p>Running on CPU, This may not work on CPU.</p>"
31
 
32
- MAX_SEED = np.iinfo(np.int32).max
33
-
34
  USE_TORCH_COMPILE = 0
35
  ENABLE_CPU_OFFLOAD = 0
36
 
@@ -40,25 +37,21 @@ style_list = [
40
  "prompt": "{prompt}",
41
  "negative_prompt": "",
42
  },
43
-
44
  {
45
  "name": "3840 x 2160",
46
  "prompt": "hyper-realistic 8K image of {prompt} . ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
47
  "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
48
  },
49
-
50
  {
51
  "name": "2560 × 1440",
52
  "prompt": "hyper-realistic 4K image of {prompt} . ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
53
  "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
54
  },
55
-
56
  {
57
  "name": "HDR",
58
  "prompt": "HDR photo of {prompt} . high dynamic range, vivid colors, sharp contrast, realistic, detailed, high resolution, professional",
59
  "negative_prompt": "dull, low contrast, blurry, unrealistic, cartoonish, ugly, deformed",
60
  },
61
-
62
  {
63
  "name": "Cinematic",
64
  "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
@@ -84,15 +77,13 @@ style_list = [
84
  "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
85
  "negative_prompt": "photo, photorealistic, realism, ugly",
86
  },
87
-
88
  {
89
  "name": "3D Model",
90
  "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
91
  "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
92
  },
 
93
 
94
-
95
- ]
96
  styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
97
  STYLE_NAMES = list(styles.keys())
98
  DEFAULT_STYLE_NAME = "(No style)"
@@ -103,7 +94,6 @@ def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str
103
  negative = ""
104
  return p.replace("{prompt}", positive), n + negative
105
 
106
- @spaces.GPU(enable_queue=True)
107
  def stab(
108
  prompt: str,
109
  negative_prompt: str = "",
@@ -118,11 +108,10 @@ def stab(
118
  randomize_seed: bool = False,
119
  progress=gr.Progress(track_tqdm=True),
120
  ):
121
-
122
  seed = int(randomize_seed_fn(seed, randomize_seed))
123
 
124
  if not use_negative_prompt:
125
- negative_prompt = "" # type: ignore
126
  prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
127
 
128
  prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", variant="bf16", torch_dtype=torch.bfloat16)
@@ -169,6 +158,7 @@ footer {
169
  visibility: hidden
170
  }
171
  '''
 
172
  with gr.Blocks(css=css, theme="xiaobaiyuan/theme_brief") as demo:
173
  gr.Markdown(DESCRIPTION)
174
  gr.DuplicateButton(
@@ -179,7 +169,7 @@ with gr.Blocks(css=css, theme="xiaobaiyuan/theme_brief") as demo:
179
 
180
  with gr.Group():
181
  with gr.Row():
182
- prompt = gr.Text(
183
  label="Prompt",
184
  show_label=False,
185
  max_lines=1,
@@ -190,14 +180,13 @@ with gr.Blocks(css=css, theme="xiaobaiyuan/theme_brief") as demo:
190
  result = gr.Gallery(label="Result", columns=1, preview=True)
191
  with gr.Accordion("Advanced options", open=False):
192
  use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
193
- negative_prompt = gr.Text(
194
- label="Negative prompt",
195
- max_lines=5,
196
- line=4,
197
- placeholder="Enter a negative prompt",
198
- value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
199
- visible=True,
200
- )
201
  with gr.Row():
202
  num_inference_steps = gr.Slider(
203
  label="Steps",
@@ -247,15 +236,14 @@ with gr.Blocks(css=css, theme="xiaobaiyuan/theme_brief") as demo:
247
  value=6,
248
  )
249
  with gr.Row(visible=True):
250
- style_selection = gr.Radio(
251
- show_label=True,
252
- container=True,
253
- interactive=True,
254
- choices=STYLE_NAMES,
255
- value=DEFAULT_STYLE_NAME,
256
- label="Image Style",
257
- )
258
-
259
 
260
  gr.Examples(
261
  examples=examples,
@@ -271,7 +259,6 @@ with gr.Blocks(css=css, theme="xiaobaiyuan/theme_brief") as demo:
271
  outputs=negative_prompt,
272
  api_name=False,
273
  )
274
-
275
 
276
  gr.on(
277
  triggers=[
@@ -296,6 +283,6 @@ with gr.Blocks(css=css, theme="xiaobaiyuan/theme_brief") as demo:
296
  outputs=[result, seed],
297
  api_name="run",
298
  )
299
-
300
  if __name__ == "__main__":
301
  demo.queue(max_size=20).launch(show_api=False, debug=False, share=True)
 
7
  import gradio as gr
8
  import numpy as np
9
  from PIL import Image
 
 
10
  import torch
11
  from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
12
+ from typing import Tuple
13
 
14
  DESCRIPTION = """ """
15
 
 
28
  if not torch.cuda.is_available():
29
  DESCRIPTION += "\n<p>Running on CPU, This may not work on CPU.</p>"
30
 
 
 
31
  USE_TORCH_COMPILE = 0
32
  ENABLE_CPU_OFFLOAD = 0
33
 
 
37
  "prompt": "{prompt}",
38
  "negative_prompt": "",
39
  },
 
40
  {
41
  "name": "3840 x 2160",
42
  "prompt": "hyper-realistic 8K image of {prompt} . ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
43
  "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
44
  },
 
45
  {
46
  "name": "2560 × 1440",
47
  "prompt": "hyper-realistic 4K image of {prompt} . ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
48
  "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
49
  },
 
50
  {
51
  "name": "HDR",
52
  "prompt": "HDR photo of {prompt} . high dynamic range, vivid colors, sharp contrast, realistic, detailed, high resolution, professional",
53
  "negative_prompt": "dull, low contrast, blurry, unrealistic, cartoonish, ugly, deformed",
54
  },
 
55
  {
56
  "name": "Cinematic",
57
  "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
 
77
  "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
78
  "negative_prompt": "photo, photorealistic, realism, ugly",
79
  },
 
80
  {
81
  "name": "3D Model",
82
  "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
83
  "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
84
  },
85
+ ]
86
 
 
 
87
  styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
88
  STYLE_NAMES = list(styles.keys())
89
  DEFAULT_STYLE_NAME = "(No style)"
 
94
  negative = ""
95
  return p.replace("{prompt}", positive), n + negative
96
 
 
97
  def stab(
98
  prompt: str,
99
  negative_prompt: str = "",
 
108
  randomize_seed: bool = False,
109
  progress=gr.Progress(track_tqdm=True),
110
  ):
 
111
  seed = int(randomize_seed_fn(seed, randomize_seed))
112
 
113
  if not use_negative_prompt:
114
+ negative_prompt = ""
115
  prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
116
 
117
  prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", variant="bf16", torch_dtype=torch.bfloat16)
 
158
  visibility: hidden
159
  }
160
  '''
161
+
162
  with gr.Blocks(css=css, theme="xiaobaiyuan/theme_brief") as demo:
163
  gr.Markdown(DESCRIPTION)
164
  gr.DuplicateButton(
 
169
 
170
  with gr.Group():
171
  with gr.Row():
172
+ prompt = gr.Textbox(
173
  label="Prompt",
174
  show_label=False,
175
  max_lines=1,
 
180
  result = gr.Gallery(label="Result", columns=1, preview=True)
181
  with gr.Accordion("Advanced options", open=False):
182
  use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
183
+ negative_prompt = gr.Textbox(
184
+ label="Negative prompt",
185
+ max_lines=5,
186
+ placeholder="Enter a negative prompt",
187
+ value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
188
+ visible=True,
189
+ )
 
190
  with gr.Row():
191
  num_inference_steps = gr.Slider(
192
  label="Steps",
 
236
  value=6,
237
  )
238
  with gr.Row(visible=True):
239
+ style_selection = gr.Radio(
240
+ show_label=True,
241
+ container=True,
242
+ interactive=True,
243
+ choices=STYLE_NAMES,
244
+ value=DEFAULT_STYLE_NAME,
245
+ label="Image Style",
246
+ )
 
247
 
248
  gr.Examples(
249
  examples=examples,
 
259
  outputs=negative_prompt,
260
  api_name=False,
261
  )
 
262
 
263
  gr.on(
264
  triggers=[
 
283
  outputs=[result, seed],
284
  api_name="run",
285
  )
286
+
287
  if __name__ == "__main__":
288
  demo.queue(max_size=20).launch(show_api=False, debug=False, share=True)