ensure image is a png
Browse files
webgui.py
CHANGED
|
@@ -137,6 +137,20 @@ pipe = Audio2VideoPipeline(
|
|
| 137 |
scheduler=scheduler,
|
| 138 |
).to("cuda", dtype=weight_dtype)
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
def select_face(det_bboxes, probs):
|
| 141 |
## max face from faces that the prob is above 0.8
|
| 142 |
## box: xyxy
|
|
@@ -158,7 +172,9 @@ def process_video(uploaded_img, uploaded_audio, width, height, length, seed, fac
|
|
| 158 |
else:
|
| 159 |
generator = torch.manual_seed(random.randint(100, 1000000))
|
| 160 |
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
face_img = cv2.imread(uploaded_img)
|
| 163 |
|
| 164 |
# Get the original dimensions
|
|
|
|
| 137 |
scheduler=scheduler,
|
| 138 |
).to("cuda", dtype=weight_dtype)
|
| 139 |
|
| 140 |
+
def ensure_png(image_path):
|
| 141 |
+
# Load the image with Pillow
|
| 142 |
+
with Image.open(image_path) as img:
|
| 143 |
+
# Check if the image is already a PNG
|
| 144 |
+
if img.format != "PNG":
|
| 145 |
+
# Convert and save as PNG
|
| 146 |
+
png_path = os.path.splitext(image_path)[0] + ".png"
|
| 147 |
+
img.save(png_path, format="PNG")
|
| 148 |
+
print(f"Image converted to PNG and saved as {png_path}")
|
| 149 |
+
return png_path
|
| 150 |
+
else:
|
| 151 |
+
print("Image is already a PNG.")
|
| 152 |
+
return image_path
|
| 153 |
+
|
| 154 |
def select_face(det_bboxes, probs):
|
| 155 |
## max face from faces that the prob is above 0.8
|
| 156 |
## box: xyxy
|
|
|
|
| 172 |
else:
|
| 173 |
generator = torch.manual_seed(random.randint(100, 1000000))
|
| 174 |
|
| 175 |
+
uploaded_img = ensure_png(uploaded_img)
|
| 176 |
+
|
| 177 |
+
#### face mask prepare
|
| 178 |
face_img = cv2.imread(uploaded_img)
|
| 179 |
|
| 180 |
# Get the original dimensions
|