rphrp1985 commited on
Commit
7456e61
1 Parent(s): 04d8ef1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -1
app.py CHANGED
@@ -19,14 +19,50 @@ repo = "SG161222/RealVisXL_V4.0"
19
  pipeline = AutoPipelineForText2Image.from_pretrained(repo, torch_dtype=torch.float16).to('cuda')
20
 
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  MAX_SEED = np.iinfo(np.int32).max
23
- MAX_IMAGE_SIZE = 1344
24
 
25
  @spaces.GPU(duration=60)
26
  def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
27
 
28
  if randomize_seed:
29
  seed = random.randint(0, MAX_SEED)
 
 
 
 
30
 
31
  generator = torch.Generator().manual_seed(seed)
32
  image = pipeline(prompt = prompt,
 
19
  pipeline = AutoPipelineForText2Image.from_pretrained(repo, torch_dtype=torch.float16).to('cuda')
20
 
21
 
22
+ def adjust_to_nearest_multiple(value, divisor=8):
23
+ """
24
+ Adjusts the input value to the nearest multiple of the divisor.
25
+
26
+ Args:
27
+ value (int): The value to adjust.
28
+ divisor (int): The divisor to which the value should be divisible. Default is 8.
29
+ Returns:
30
+ int: The nearest multiple of the divisor.
31
+ """
32
+ if value % divisor == 0:
33
+ return value
34
+ else:
35
+ # Round to the nearest multiple of divisor
36
+ return round(value / divisor) * divisor
37
+
38
+ def adjust_dimensions(height, width):
39
+ """
40
+ Adjusts the height and width to be divisible by 8.
41
+
42
+ Args:
43
+ height (int): The height to adjust.
44
+ width (int): The width to adjust.
45
+ Returns:
46
+ tuple: Adjusted height and width.
47
+ """
48
+ new_height = adjust_to_nearest_multiple(height)
49
+ new_width = adjust_to_nearest_multiple(width)
50
+
51
+ return new_height, new_width
52
+
53
+
54
  MAX_SEED = np.iinfo(np.int32).max
55
+ MAX_IMAGE_SIZE = 4100
56
 
57
  @spaces.GPU(duration=60)
58
  def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
59
 
60
  if randomize_seed:
61
  seed = random.randint(0, MAX_SEED)
62
+
63
+ width = min(width, MAX_IMAGE_SIZE // 2)
64
+ height = min(height, MAX_IMAGE_SIZE // 2)
65
+ height, width = adjust_dimensions(height, width)
66
 
67
  generator = torch.Generator().manual_seed(seed)
68
  image = pipeline(prompt = prompt,