ford442 commited on
Commit
c1d4f17
·
verified ·
1 Parent(s): 414ab4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -136,34 +136,38 @@ def upload_to_sftp(local_filepath):
136
 
137
 
138
  def calculate_new_dimensions(orig_w, orig_h):
139
- if orig_w == 0 or orig_h == 0: return int(768), int(768)
140
  if orig_w >= orig_h:
141
- new_h, new_w = 768, round((768 * (orig_w / orig_h)) / 32) * 32
142
  else:
143
- new_w, new_h = 768, round((768 * (orig_h / orig_w)) / 32) * 32
144
  return int(max(256, min(new_h, MAX_IMAGE_SIZE))), int(max(256, min(new_w, MAX_IMAGE_SIZE)))
145
 
146
 
147
  def get_duration(*args, **kwargs):
148
  duration_ui = kwargs.get('duration_ui', 5.0)
149
- if duration_ui > 7.0: return 120
150
  if duration_ui > 5.0: return 100
 
 
 
 
 
 
151
  return 90
152
 
153
- @spaces.GPU(duration=30)
154
  def superres_image(image_to_enhance: Image.Image):
155
  print("Doing super-resolution.")
156
-
157
  torch.backends.cuda.matmul.allow_tf32 = True
158
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = True
159
  torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = True
160
  torch.backends.cudnn.allow_tf32 = True
161
  torch.backends.cudnn.deterministic = True
162
  torch.set_float32_matmul_precision("high")
163
-
164
 
165
  with torch.no_grad():
166
- upscale = upscaler(enhanced_image, tiling=True, tile_width=1024, tile_height=1024)
167
  enhanced_image = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
168
  return enhanced_image
169
 
@@ -181,10 +185,7 @@ def enhance_frame(prompt, image_to_enhance: Image.Image):
181
  torch.backends.cudnn.allow_tf32 = True
182
  torch.backends.cudnn.deterministic = True
183
  torch.set_float32_matmul_precision("high")
184
-
185
-
186
-
187
- enhanced_image = enhancer_pipeline(prompt=refine_prompt, image=image_to_enhance, strength=0.1, generator=generator, num_inference_steps=160).images[0]
188
  print("Frame enhancement successful.")
189
  except Exception as e:
190
  print(f"Error during frame enhancement: {e}")
 
136
 
137
 
138
  def calculate_new_dimensions(orig_w, orig_h):
139
+ if orig_w == 0 or orig_h == 0: return int(1024), int(1024)
140
  if orig_w >= orig_h:
141
+ new_h, new_w = 1024, round((1024 * (orig_w / orig_h)) / 32) * 32
142
  else:
143
+ new_w, new_h = 1024, round((1024 * (orig_h / orig_w)) / 32) * 32
144
  return int(max(256, min(new_h, MAX_IMAGE_SIZE))), int(max(256, min(new_w, MAX_IMAGE_SIZE)))
145
 
146
 
147
  def get_duration(*args, **kwargs):
148
  duration_ui = kwargs.get('duration_ui', 5.0)
149
+ if duration_ui > 7.0: return 110
150
  if duration_ui > 5.0: return 100
151
+ if duration_ui > 4.0: return 90
152
+ if duration_ui > 3.0: return 70
153
+ if duration_ui > 2.0: return 60
154
+ if duration_ui > 1.5: return 50
155
+ if duration_ui > 1.0: return 45
156
+ if duration_ui > 0.5: return 30
157
  return 90
158
 
159
+ @spaces.GPU(duration=20)
160
  def superres_image(image_to_enhance: Image.Image):
161
  print("Doing super-resolution.")
 
162
  torch.backends.cuda.matmul.allow_tf32 = True
163
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = True
164
  torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = True
165
  torch.backends.cudnn.allow_tf32 = True
166
  torch.backends.cudnn.deterministic = True
167
  torch.set_float32_matmul_precision("high")
 
168
 
169
  with torch.no_grad():
170
+ upscale = upscaler(image_to_enhance, tiling=True, tile_width=1024, tile_height=1024)
171
  enhanced_image = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
172
  return enhanced_image
173
 
 
185
  torch.backends.cudnn.allow_tf32 = True
186
  torch.backends.cudnn.deterministic = True
187
  torch.set_float32_matmul_precision("high")
188
+ enhanced_image = enhancer_pipeline(prompt=refine_prompt, image=image_to_enhance, strength=0.15, generator=generator, num_inference_steps=220).images[0]
 
 
 
189
  print("Frame enhancement successful.")
190
  except Exception as e:
191
  print(f"Error during frame enhancement: {e}")