prithivMLmods commited on
Commit
7722042
·
verified ·
1 Parent(s): 6f61338

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -14,10 +14,15 @@ DESCRIPTIONx = """## STABLE HAMSTER 🐹
14
  """
15
 
16
  css = '''
17
- .gradio-container{max-width: 560px !important}
18
- h1{text-align:center}
 
 
 
 
 
19
  footer {
20
- visibility: hidden
21
  }
22
  '''
23
 
@@ -27,17 +32,15 @@ examples = [
27
  "Vector illustration of a horse, vector graphic design with flat colors on an brown background in the style of vector art, using simple shapes and graphics with simple details, professionally designed as a tshirt logo ready for print on a white background. --ar 89:82 --v 6.0 --style raw",
28
  "Man in brown leather jacket posing for camera, in the style of sleek and stylized, clockpunk, subtle shades, exacting precision, ferrania p30 --ar 67:101 --v 5",
29
  "Commercial photography, giant burger, white lighting, studio light, 8k octane rendering, high resolution photography, insanely detailed, fine details, on white isolated plain, 8k, commercial photography, stock photo, professional color grading, --v 4 --ar 9:16 "
30
-
31
  ]
32
 
33
-
34
- MODEL_ID = os.getenv("MODEL_VAL_PATH") #uses SG161222/RealVisXL_V5.0_Lightning or SG161222/RealVisXL_V4.0_Lightning
35
  MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
36
  USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
37
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
38
  BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1")) # Allow generating multiple images at once
39
 
40
- #Load model outside of function
41
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
42
  pipe = StableDiffusionXLPipeline.from_pretrained(
43
  MODEL_ID,
@@ -78,14 +81,14 @@ def generate(
78
  guidance_scale: float = 3,
79
  num_inference_steps: int = 25,
80
  randomize_seed: bool = False,
81
- use_resolution_binning: bool = True,
82
  num_images: int = 4, # Number of images to generate
83
  progress=gr.Progress(track_tqdm=True),
84
  ):
85
  seed = int(randomize_seed_fn(seed, randomize_seed))
86
  generator = torch.Generator(device=device).manual_seed(seed)
87
 
88
- #Options
89
  options = {
90
  "prompt": [prompt] * num_images,
91
  "negative_prompt": [negative_prompt] * num_images if use_negative_prompt else None,
@@ -100,7 +103,7 @@ def generate(
100
  if use_resolution_binning:
101
  options["use_resolution_binning"] = True
102
 
103
- #Images potential batches
104
  images = []
105
  for i in range(0, num_images, BATCH_SIZE):
106
  batch_options = options.copy()
@@ -113,7 +116,7 @@ def generate(
113
  return image_paths, seed
114
 
115
  with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
116
- gr.Markdown(DESCRIPTIONx)
117
  with gr.Group():
118
  with gr.Row():
119
  prompt = gr.Text(
@@ -124,7 +127,7 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
124
  container=False,
125
  )
126
  run_button = gr.Button("Run", scale=0)
127
- result = gr.Gallery(label="Result", columns=2, show_label=False)
128
  with gr.Accordion("Advanced options", open=False, visible=True):
129
  num_images = gr.Slider(
130
  label="Number of Images",
@@ -216,7 +219,7 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
216
  ],
217
  outputs=[result, seed],
218
  api_name="run",
219
- )
220
 
221
  if __name__ == "__main__":
222
  demo.queue(max_size=40).launch(ssr_mode=False)
 
14
  """
15
 
16
  css = '''
17
+ .gradio-container {
18
+ max-width: 560px !important;
19
+ margin: 0 auto !important;
20
+ }
21
+ h1 {
22
+ text-align: center;
23
+ }
24
  footer {
25
+ visibility: hidden;
26
  }
27
  '''
28
 
 
32
  "Vector illustration of a horse, vector graphic design with flat colors on an brown background in the style of vector art, using simple shapes and graphics with simple details, professionally designed as a tshirt logo ready for print on a white background. --ar 89:82 --v 6.0 --style raw",
33
  "Man in brown leather jacket posing for camera, in the style of sleek and stylized, clockpunk, subtle shades, exacting precision, ferrania p30 --ar 67:101 --v 5",
34
  "Commercial photography, giant burger, white lighting, studio light, 8k octane rendering, high resolution photography, insanely detailed, fine details, on white isolated plain, 8k, commercial photography, stock photo, professional color grading, --v 4 --ar 9:16 "
 
35
  ]
36
 
37
+ MODEL_ID = os.getenv("MODEL_VAL_PATH") # uses SG161222/RealVisXL_V5.0_Lightning or SG161222/RealVisXL_V4.0_Lightning
 
38
  MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
39
  USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
40
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
41
  BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1")) # Allow generating multiple images at once
42
 
43
+ # Load model outside of function
44
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
45
  pipe = StableDiffusionXLPipeline.from_pretrained(
46
  MODEL_ID,
 
81
  guidance_scale: float = 3,
82
  num_inference_steps: int = 25,
83
  randomize_seed: bool = False,
84
+ use_resolution_binning: bool = True,
85
  num_images: int = 4, # Number of images to generate
86
  progress=gr.Progress(track_tqdm=True),
87
  ):
88
  seed = int(randomize_seed_fn(seed, randomize_seed))
89
  generator = torch.Generator(device=device).manual_seed(seed)
90
 
91
+ # Options
92
  options = {
93
  "prompt": [prompt] * num_images,
94
  "negative_prompt": [negative_prompt] * num_images if use_negative_prompt else None,
 
103
  if use_resolution_binning:
104
  options["use_resolution_binning"] = True
105
 
106
+ # Images potential batches
107
  images = []
108
  for i in range(0, num_images, BATCH_SIZE):
109
  batch_options = options.copy()
 
116
  return image_paths, seed
117
 
118
  with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
119
+ gr.Markdown(DESCRIPTIONx)
120
  with gr.Group():
121
  with gr.Row():
122
  prompt = gr.Text(
 
127
  container=False,
128
  )
129
  run_button = gr.Button("Run", scale=0)
130
+ result = gr.Gallery(label="Result", columns=2, show_label=False)
131
  with gr.Accordion("Advanced options", open=False, visible=True):
132
  num_images = gr.Slider(
133
  label="Number of Images",
 
219
  ],
220
  outputs=[result, seed],
221
  api_name="run",
222
+ )
223
 
224
  if __name__ == "__main__":
225
  demo.queue(max_size=40).launch(ssr_mode=False)