Jannat24 commited on
Commit
7430abb
·
verified ·
1 Parent(s): f233ca1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -43,10 +43,15 @@ def gen_sources(deepfake_img):
43
  #----------------DeepFake Face Segmentation-----------------
44
  ##----------------------Initialize:Face Segmentation----------------------------------
45
  segmenter = FaceSegmenter(threshold=0.5)
46
- deepfake_seg = segmenter.segment_face(deepfake_img)
47
-
48
- config_path = "./models/config.yaml"
 
 
 
 
49
  #------------Initialize:Decoder-F------------------------
 
50
  checkpoint_path_f = "./models/model_vaq1_ff.pth"
51
  checkpoint_f = torch.load(checkpoint_path_f, map_location=device)
52
  model_vaq_f = Generator(config_path, device)
 
43
  #----------------DeepFake Face Segmentation-----------------
44
  ##----------------------Initialize:Face Segmentation----------------------------------
45
  segmenter = FaceSegmenter(threshold=0.5)
46
+ # Convert PIL Image to BGR numpy array for segmentation
47
+ img_np = np.array(deepfake_img.convert('RGB'))
48
+ img_bgr = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
49
+ # Segment the face
50
+ segmented_np = segmenter.segment_face(img_bgr)
51
+ # Convert segmented numpy array (BGR) back to PIL Image
52
+ deepfake_seg = Image.fromarray(cv2.cvtColor(segmented_np, cv2.COLOR_BGR2RGB))
53
  #------------Initialize:Decoder-F------------------------
54
+ config_path = "./models/config.yaml"
55
  checkpoint_path_f = "./models/model_vaq1_ff.pth"
56
  checkpoint_f = torch.load(checkpoint_path_f, map_location=device)
57
  model_vaq_f = Generator(config_path, device)