Malaji71 commited on
Commit
141e3f6
·
verified ·
1 Parent(s): 81a2bdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -179,6 +179,9 @@ def upscale_image_4k(input_path, output_path):
179
  h, w = image.shape[:2]
180
  log_message(f"📏 Original resolution: {w}x{h}")
181
 
 
 
 
182
  # Check GPU memory availability
183
  if torch.cuda.is_available():
184
  device = torch.device('cuda')
@@ -199,9 +202,6 @@ def upscale_image_4k(input_path, output_path):
199
 
200
  log_message("🧠 Applying neural upscaling...")
201
 
202
- # Progressive upscaling for better quality
203
- target_h, target_w = h * 4, w * 4
204
-
205
  with torch.no_grad():
206
  # Step 1: 2x upscaling with bicubic
207
  intermediate = torch.nn.functional.interpolate(
@@ -299,7 +299,6 @@ def upscale_image_4k(input_path, output_path):
299
  else:
300
  # CPU fallback
301
  log_message("⚠️ Using CPU - optimized processing")
302
- target_h, target_w = h * 4, w * 4
303
 
304
  # Progressive upscaling on CPU
305
  intermediate = cv2.resize(image, (w * 2, h * 2), interpolation=cv2.INTER_CUBIC)
@@ -314,6 +313,23 @@ def upscale_image_4k(input_path, output_path):
314
 
315
  cv2.imwrite(output_path, final_result)
316
  log_message(f"✅ CPU upscaling completed: {target_w}x{target_h}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
 
318
  # Add to processed files list
319
  app_state["processed_files"].append({
 
179
  h, w = image.shape[:2]
180
  log_message(f"📏 Original resolution: {w}x{h}")
181
 
182
+ # Define target dimensions first
183
+ target_h, target_w = h * 4, w * 4
184
+
185
  # Check GPU memory availability
186
  if torch.cuda.is_available():
187
  device = torch.device('cuda')
 
202
 
203
  log_message("🧠 Applying neural upscaling...")
204
 
 
 
 
205
  with torch.no_grad():
206
  # Step 1: 2x upscaling with bicubic
207
  intermediate = torch.nn.functional.interpolate(
 
299
  else:
300
  # CPU fallback
301
  log_message("⚠️ Using CPU - optimized processing")
 
302
 
303
  # Progressive upscaling on CPU
304
  intermediate = cv2.resize(image, (w * 2, h * 2), interpolation=cv2.INTER_CUBIC)
 
313
 
314
  cv2.imwrite(output_path, final_result)
315
  log_message(f"✅ CPU upscaling completed: {target_w}x{target_h}")
316
+ else:
317
+ # CPU only fallback (no CUDA available)
318
+ log_message("💻 Using CPU processing (CUDA not available)")
319
+
320
+ # Progressive upscaling on CPU
321
+ intermediate = cv2.resize(image, (w * 2, h * 2), interpolation=cv2.INTER_CUBIC)
322
+ upscaled = cv2.resize(intermediate, (target_w, target_h), interpolation=cv2.INTER_CUBIC)
323
+
324
+ # Apply sharpening on CPU
325
+ kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
326
+ sharpened = cv2.filter2D(upscaled, -1, kernel)
327
+
328
+ # Blend for smoothing
329
+ final_result = cv2.addWeighted(upscaled, 0.7, sharpened, 0.3, 0)
330
+
331
+ cv2.imwrite(output_path, final_result)
332
+ log_message(f"✅ CPU upscaling completed: {target_w}x{target_h}")
333
 
334
  # Add to processed files list
335
  app_state["processed_files"].append({