Spaces:
Sleeping
Sleeping
2025_march17
Browse files
app.py
CHANGED
@@ -43,6 +43,10 @@ def gen_sources(deepfake_img):
|
|
43 |
#----------------DeepFake Face Segmentation-----------------
|
44 |
##----------------------Initialize:Face Segmentation----------------------------------
|
45 |
segmenter = FaceSegmenter(threshold=0.5)
|
|
|
|
|
|
|
|
|
46 |
# Save PIL Image to temporary file
|
47 |
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_file:
|
48 |
temp_path = temp_file.name
|
@@ -91,10 +95,8 @@ def gen_sources(deepfake_img):
|
|
91 |
z_seg, _, _ = model_vaq_g.encode(seg_img)
|
92 |
rec_z_img1 = model_z1(z_df)
|
93 |
rec_z_img2 = model_z2(z_seg)
|
94 |
-
rec_img1 = model_vaq_f.decode(rec_z_img1)
|
95 |
-
rec_img2 = model_vaq_g.decode(rec_z_img2)
|
96 |
-
rec_img1 = rec_img1.squeeze(0)
|
97 |
-
rec_img2 = rec_img2.squeeze(0)
|
98 |
rec_img1_pil = T.ToPILImage()(rec_img1)
|
99 |
rec_img2_pil = T.ToPILImage()(rec_img2)
|
100 |
|
|
|
43 |
#----------------DeepFake Face Segmentation-----------------
|
44 |
##----------------------Initialize:Face Segmentation----------------------------------
|
45 |
segmenter = FaceSegmenter(threshold=0.5)
|
46 |
+
#Convert Pillow Image to OpenCV Image (BGR format)
|
47 |
+
dfcv2_image = np.array(deepfake_img) # Convert PIL to numpy array (RGB)
|
48 |
+
dfcv2_image = cv2.cvtColor(dfcv2_image, cv2.COLOR_RGB2BGR) # Convert RGB to BGR
|
49 |
+
deepfake_seg = segmenter.segment_face(dfcv2_image)
|
50 |
# Save PIL Image to temporary file
|
51 |
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_file:
|
52 |
temp_path = temp_file.name
|
|
|
95 |
z_seg, _, _ = model_vaq_g.encode(seg_img)
|
96 |
rec_z_img1 = model_z1(z_df)
|
97 |
rec_z_img2 = model_z2(z_seg)
|
98 |
+
rec_img1 = model_vaq_f.decode(rec_z_img1).squeeze(0)
|
99 |
+
rec_img2 = model_vaq_g.decode(rec_z_img2).squeeze(0)
|
|
|
|
|
100 |
rec_img1_pil = T.ToPILImage()(rec_img1)
|
101 |
rec_img2_pil = T.ToPILImage()(rec_img2)
|
102 |
|