Download process_broll_watermarks.py from aoiandroid/android-times-articles: direct link, hf CLI and curl.
- Browser
- Download file 3.76 kB
-
https://huggingface.co/datasets/aoiandroid/android-times-articles/resolve/main/process_broll_watermarks.py
- Command line
-
hf download hf://datasets/aoiandroid/android-times-articles/process_broll_watermarks.py
-
curl -L -o process_broll_watermarks.py https://huggingface.co/datasets/aoiandroid/android-times-articles/resolve/main/process_broll_watermarks.py
3.76 kB
| import os | |
| import sys | |
| import shutil | |
| from pathlib import Path | |
| import logging | |
| # Set up logging | |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | |
| logger = logging.getLogger("process_broll_watermarks") | |
| # Add ComfyUI Articles directory to sys.path | |
| sys.path.append(r"C:\ComfyUI\Articles") | |
| from quality_gate_broll import detect_watermarks, remove_watermark_with_lama | |
| from collect_broll_agent import generate_ken_burns_clip | |
| ROOT_DIR = Path(r"C:\ComfyUI\Articles") | |
| def main(): | |
| logger.info("Scanning for existing B-roll images in Articles directory...") | |
| # Walk through ROOT_DIR to find Broll folders | |
| broll_images = [] | |
| for root, dirs, files in os.walk(ROOT_DIR): | |
| if Path(root).name == "Broll": | |
| for f in files: | |
| f_path = Path(root) / f | |
| # Target only jpg/png images, skipping temporary files, masks, and originals | |
| if f_path.suffix.lower() in [".jpg", ".jpeg", ".png"]: | |
| if f.startswith("tmp_") or f.startswith("std_") or "_original" in f or "_mask" in f: | |
| continue | |
| broll_images.append(f_path) | |
| logger.info(f"Found {len(broll_images)} candidate B-roll images.") | |
| flagged_count = 0 | |
| removed_count = 0 | |
| regenerated_count = 0 | |
| for i, img_path in enumerate(broll_images, 1): | |
| logger.info(f"[{i}/{len(broll_images)}] Scanning {img_path.relative_to(ROOT_DIR)}") | |
| detected_corners = detect_watermarks(img_path) | |
| if detected_corners: | |
| flagged_count += 1 | |
| logger.info(f" -> Watermark detected in corners: {detected_corners}") | |
| # Backup original image if not already done | |
| backup_path = img_path.parent / f"{img_path.name.replace(img_path.suffix, '')}_original{img_path.suffix}" | |
| if not backup_path.exists(): | |
| shutil.copy2(img_path, backup_path) | |
| logger.info(f" -> Created backup: {backup_path.name}") | |
| # Perform watermark removal using LaMa | |
| # We pass backup_path as input and img_path as output, so we always inpaint from the clean original | |
| success, reason = remove_watermark_with_lama(backup_path, img_path) | |
| if success: | |
| removed_count += 1 | |
| logger.info(f" -> Successfully removed watermark from {img_path.name}") | |
| # Check for corresponding mp4 clip to regenerate | |
| mp4_path = img_path.parent / f"{img_path.stem}.mp4" | |
| if mp4_path.exists(): | |
| logger.info(f" -> Corresponding video clip found: {mp4_path.name}. Regenerating...") | |
| # Re-render clip from the watermarked-free image | |
| if generate_ken_burns_clip(img_path, mp4_path): | |
| regenerated_count += 1 | |
| logger.info(f" -> Successfully regenerated video clip: {mp4_path.name}") | |
| else: | |
| logger.error(f" -> Failed to regenerate video clip: {mp4_path.name}") | |
| else: | |
| logger.warning(f" -> Watermark removal failed: {reason}") | |
| logger.info("========================================") | |
| logger.info("Watermark Processing Finished.") | |
| logger.info(f"Total images scanned: {len(broll_images)}") | |
| logger.info(f"Images flagged with watermarks: {flagged_count}") | |
| logger.info(f"Images successfully inpainted: {removed_count}") | |
| logger.info(f"Video clips successfully regenerated: {regenerated_count}") | |
| logger.info("========================================") | |
| if __name__ == "__main__": | |
| main() | |