Aklavya commited on
Commit
4d4bca8
·
verified ·
1 Parent(s): 36a1c8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -39,7 +39,7 @@ def check_for_adult_content(image):
39
 
40
  return False # No explicit content detected
41
 
42
- # Face swapping function with added smoothing
43
  def swap_faces(destination_image, source_image):
44
  # Load the destination and source images from Streamlit inputs
45
  img = cv2.cvtColor(np.array(destination_image), cv2.COLOR_RGB2BGR)
@@ -62,19 +62,19 @@ def swap_faces(destination_image, source_image):
62
  except MemoryError:
63
  return "Memory error: Face swapping operation failed due to memory overload."
64
 
65
- # Commented sharpening for testing purposes
66
- # kernel = np.array([[0, -1, 0],
67
- # [-1, 5, -1],
68
- # [0, -1, 0]])
69
- # sharpened_res = cv2.filter2D(res, -1, kernel)
70
 
71
- # Add smoothing (blurring) for a more natural look
72
- smoothed_res = cv2.GaussianBlur(res, (5, 5), 0)
73
 
74
  # Convert the result to RGB for display in Streamlit
75
- smoothed_res_rgb = cv2.cvtColor(smoothed_res, cv2.COLOR_BGR2RGB)
76
 
77
- return smoothed_res_rgb
78
 
79
  # Streamlit app layout
80
  def main():
 
39
 
40
  return False # No explicit content detected
41
 
42
+ # Face swapping function with added sharpening
43
  def swap_faces(destination_image, source_image):
44
  # Load the destination and source images from Streamlit inputs
45
  img = cv2.cvtColor(np.array(destination_image), cv2.COLOR_RGB2BGR)
 
62
  except MemoryError:
63
  return "Memory error: Face swapping operation failed due to memory overload."
64
 
65
+ # Apply sharpening for a clearer image
66
+ kernel = np.array([[0, -1, 0],
67
+ [-1, 5, -1],
68
+ [0, -1, 0]])
69
+ sharpened_res = cv2.filter2D(res, -1, kernel)
70
 
71
+ # Commented smoothing (blurring) for testing purposes
72
+ # smoothed_res = cv2.GaussianBlur(res, (5, 5), 0)
73
 
74
  # Convert the result to RGB for display in Streamlit
75
+ sharpened_res_rgb = cv2.cvtColor(sharpened_res, cv2.COLOR_BGR2RGB)
76
 
77
+ return sharpened_res_rgb
78
 
79
  # Streamlit app layout
80
  def main():