prithivMLmods commited on
Commit
8e5ae95
·
verified ·
1 Parent(s): 9278cbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -27
app.py CHANGED
@@ -9,7 +9,7 @@ import spaces
9
  import torch
10
  from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
11
 
12
- DESCRIPTIONx = """## REALVISXL V5 🦉
13
  """
14
 
15
  css = '''
@@ -25,11 +25,11 @@ examples = [
25
  "Cold coffee in a cup bokeh --ar 85:128 --v 6.0 --style raw5, 4K",
26
  ]
27
 
28
- MODEL_ID = os.getenv("MODEL_VAL_PATH", "SG161222/RealVisXL_V4.0_Lightning")
29
  MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
30
  USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
31
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
32
- BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1"))
33
 
34
  #Load model outside of function
35
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
@@ -61,18 +61,6 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
61
  seed = random.randint(0, MAX_SEED)
62
  return seed
63
 
64
- def set_wallpaper_size(size):
65
- if size == "Mobile (1080x1920)":
66
- return 1080, 1920
67
- elif size == "Desktop (1920x1080)":
68
- return 1920, 1080
69
- elif size == "Extented (1920x512)":
70
- return 1920, 512
71
- elif size == "Headers (1080x512)":
72
- return 1080, 512
73
- else:
74
- return 1024, 1024
75
-
76
  @spaces.GPU(duration=60, enable_queue=True)
77
  def generate(
78
  prompt: str,
@@ -81,7 +69,6 @@ def generate(
81
  seed: int = 1,
82
  width: int = 1024,
83
  height: int = 1024,
84
- wallpaper_size: str = "Default (1024x1024)",
85
  guidance_scale: float = 3,
86
  num_inference_steps: int = 25,
87
  randomize_seed: bool = False,
@@ -91,9 +78,8 @@ def generate(
91
  ):
92
  seed = int(randomize_seed_fn(seed, randomize_seed))
93
  generator = torch.Generator(device=device).manual_seed(seed)
94
- width, height = set_wallpaper_size(wallpaper_size)
95
 
96
-
97
  options = {
98
  "prompt": [prompt] * num_images,
99
  "negative_prompt": [negative_prompt] * num_images if use_negative_prompt else None,
@@ -120,9 +106,10 @@ def generate(
120
 
121
  image_paths = [save_image(img) for img in images]
122
  return image_paths, seed
123
-
124
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
125
  gr.Markdown(DESCRIPTIONx)
 
126
  with gr.Group():
127
  with gr.Row():
128
  prompt = gr.Text(
@@ -134,13 +121,6 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
134
  )
135
  run_button = gr.Button("Run", scale=0)
136
  result = gr.Gallery(label="Result", columns=1, show_label=False)
137
-
138
- with gr.Row(visible=True):
139
- wallpaper_size = gr.Radio(
140
- choices=["Mobile (1080x1920)", "Desktop (1920x1080)", "Extented (1920x512)", "Headers (1080x512)", "Default (1024x1024)"],
141
- label="Pixel Size(x*y)",
142
- value="Default (1024x1024)"
143
- )
144
  with gr.Accordion("Advanced options", open=False, visible=False):
145
  num_images = gr.Slider(
146
  label="Number of Images",
@@ -232,6 +212,6 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
232
  outputs=[result, seed],
233
  api_name="run",
234
  )
235
-
236
  if __name__ == "__main__":
237
  demo.queue(max_size=40).launch()
 
9
  import torch
10
  from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
11
 
12
+ DESCRIPTIONx = """## REALVISXL V5 🤗
13
  """
14
 
15
  css = '''
 
25
  "Cold coffee in a cup bokeh --ar 85:128 --v 6.0 --style raw5, 4K",
26
  ]
27
 
28
+ MODEL_ID = os.getenv("MODEL_VAL_PATH", "SG161222/RealVisXL_V4.0_Lightning")
29
  MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
30
  USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
31
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
32
+ BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1")) # Allow generating multiple images at once
33
 
34
  #Load model outside of function
35
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
 
61
  seed = random.randint(0, MAX_SEED)
62
  return seed
63
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  @spaces.GPU(duration=60, enable_queue=True)
65
  def generate(
66
  prompt: str,
 
69
  seed: int = 1,
70
  width: int = 1024,
71
  height: int = 1024,
 
72
  guidance_scale: float = 3,
73
  num_inference_steps: int = 25,
74
  randomize_seed: bool = False,
 
78
  ):
79
  seed = int(randomize_seed_fn(seed, randomize_seed))
80
  generator = torch.Generator(device=device).manual_seed(seed)
 
81
 
82
+ #Options
83
  options = {
84
  "prompt": [prompt] * num_images,
85
  "negative_prompt": [negative_prompt] * num_images if use_negative_prompt else None,
 
106
 
107
  image_paths = [save_image(img) for img in images]
108
  return image_paths, seed
109
+ #Main gr.Block
110
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
111
  gr.Markdown(DESCRIPTIONx)
112
+
113
  with gr.Group():
114
  with gr.Row():
115
  prompt = gr.Text(
 
121
  )
122
  run_button = gr.Button("Run", scale=0)
123
  result = gr.Gallery(label="Result", columns=1, show_label=False)
 
 
 
 
 
 
 
124
  with gr.Accordion("Advanced options", open=False, visible=False):
125
  num_images = gr.Slider(
126
  label="Number of Images",
 
212
  outputs=[result, seed],
213
  api_name="run",
214
  )
215
+ gr.HTML(html_content)
216
  if __name__ == "__main__":
217
  demo.queue(max_size=40).launch()