ford442 commited on
Commit
93bfba2
·
verified ·
1 Parent(s): 7354f4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -18,6 +18,7 @@ from typing import Tuple
18
  import paramiko
19
  import datetime
20
  import cyper
 
21
 
22
  torch.backends.cuda.matmul.allow_tf32 = False
23
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
@@ -81,6 +82,8 @@ os.putenv('TORCH_LINALG_PREFER_CUSOLVER','1')
81
 
82
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
83
 
 
 
84
  def scheduler_swap_callback(pipeline, step_index, timestep, callback_kwargs):
85
  # adjust the batch_size of prompt_embeds according to guidance_scale
86
  if step_index == int(pipeline.num_timesteps * 0.1):
@@ -176,6 +179,9 @@ def uploadNote(prompt,num_inference_steps,guidance_scale,timestamp):
176
 
177
  code = r'''
178
 
 
 
 
179
  def scheduler_swap_callback(pipeline, step_index, timestep, callback_kwargs):
180
  # adjust the batch_size of prompt_embeds according to guidance_scale
181
  if step_index == int(pipeline.num_timesteps * 0.1):
@@ -241,7 +247,7 @@ def uploadNote(prompt,num_inference_steps,guidance_scale,timestamp):
241
 
242
  '''
243
 
244
- pyx = cyper.inline(code)
245
 
246
  @spaces.GPU(duration=30)
247
  def generate_30(
@@ -283,6 +289,13 @@ def generate_30(
283
  sd_image_path = f"rv_C_{timestamp}.png"
284
  rv_image.save(sd_image_path,optimize=False,compress_level=0)
285
  pyx.upload_to_ftp(sd_image_path)
 
 
 
 
 
 
 
286
  unique_name = str(uuid.uuid4()) + ".png"
287
  os.symlink(sd_image_path, unique_name)
288
  return [unique_name]
 
18
  import paramiko
19
  import datetime
20
  import cyper
21
+ from image_gen_aux import UpscaleWithModel
22
 
23
  torch.backends.cuda.matmul.allow_tf32 = False
24
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
 
82
 
83
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
84
 
85
+ upscaler = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
86
+
87
  def scheduler_swap_callback(pipeline, step_index, timestep, callback_kwargs):
88
  # adjust the batch_size of prompt_embeds according to guidance_scale
89
  if step_index == int(pipeline.num_timesteps * 0.1):
 
179
 
180
  code = r'''
181
 
182
+ import torch
183
+ import paramiko
184
+
185
  def scheduler_swap_callback(pipeline, step_index, timestep, callback_kwargs):
186
  # adjust the batch_size of prompt_embeds according to guidance_scale
187
  if step_index == int(pipeline.num_timesteps * 0.1):
 
247
 
248
  '''
249
 
250
+ pyx = cyper.inline(code, fast_indexing=True)
251
 
252
  @spaces.GPU(duration=30)
253
  def generate_30(
 
289
  sd_image_path = f"rv_C_{timestamp}.png"
290
  rv_image.save(sd_image_path,optimize=False,compress_level=0)
291
  pyx.upload_to_ftp(sd_image_path)
292
+ torch.set_float32_matmul_precision("medium")
293
+ with torch.no_grad():
294
+ upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
295
+ downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
296
+ downscale_path = f"rv50_upscale_{timestamp}.png"
297
+ downscale1.save(downscale_path,optimize=False,compress_level=0)
298
+ pyx.upload_to_ftp(downscale_path)
299
  unique_name = str(uuid.uuid4()) + ".png"
300
  os.symlink(sd_image_path, unique_name)
301
  return [unique_name]