Added verbosity to file integrity checks

This commit is contained in:
Osama Ghozlan 2023-06-16 14:30:21 +02:00
parent f687f7b004
commit 08f17503d5

View File

@ -84,9 +84,9 @@
"\n",
"\n",
"# Based on https://stackoverflow.com/questions/22058048/hashing-a-file-in-python\n",
"def hash_mistmatch(file, hash):\n",
"def hash_mistmatch(file_, hash):\n",
" h = hashlib.sha256()\n",
" with open(file, 'rb') as file:\n",
" with open(file_, 'rb') as file:\n",
" while True:\n",
" # Reading is buffered, so we can read smaller chunks.\n",
" chunk = file.read(h.block_size)\n",
@ -95,9 +95,9 @@
" h.update(chunk)\n",
" retry = h.hexdigest() != hash\n",
" if retry:\n",
" inf(f'\\u2718 Mismatch in hash of {file}','warning', '50px')\n",
" inf(f'\\u2718 Mismatch in hash of {file_}','warning', '200px')\n",
" else:\n",
" inf(f'\\u2714 Verified integrity of {file} successfully','info', '50px')\n",
" inf(f'\\u2714 Verified integrity of {file_} successfully','info', '200px')\n",
" return retry\n",
"\n",
"\n",
@ -115,23 +115,27 @@
" !mkdir /content/gdrive/MyDrive/roop_output\n",
"\n",
" # Suggested by @phineas-pta\n",
" retry_count = 0\n",
" while retry_count < 3:\n",
"retry_count = 0\n",
"while retry_count < 3:\n",
" with capture.capture_output() as cap:\n",
" !wget -P ~/.opennsfw2 https://github.com/bhky/opennsfw2/releases/download/v0.1.0/open_nsfw_weights.h5\n",
" if not hash_mistmatch('/root/.opennsfw2/open_nsfw_weights.h5', '14ca261f48bdd88c1eecba96a761bd1579b523adae1b749b0a4ffd8b7ed8babe'):\n",
" retry_count = 0\n",
" break\n",
" retry_count += 1\n",
" while retry_count < 3:\n",
" if not hash_mistmatch('/root/.opennsfw2/open_nsfw_weights.h5', '14ca261f48bdd88c1eecba96a761bd1579b523adae1b749b0a4ffd8b7ed8babe'):\n",
" retry_count = 0\n",
" break\n",
" retry_count += 1\n",
"while retry_count < 3:\n",
" with capture.capture_output() as cap:\n",
" !wget -P ~/.insightface/models https://github.com/deepinsight/insightface/releases/download/v0.7/buffalo_l.zip\n",
" if not hash_mistmatch('/root/.insightface/models/buffalo_l.zip', '80ffe37d8a5940d59a7384c201a2a38d4741f2f3c51eef46ebb28218a7b0ca2f'):\n",
" retry_count = 0\n",
" break\n",
" retry_count += 1\n",
" if not hash_mistmatch('/root/.insightface/models/buffalo_l.zip', '80ffe37d8a5940d59a7384c201a2a38d4741f2f3c51eef46ebb28218a7b0ca2f'):\n",
" retry_count = 0\n",
" break\n",
" retry_count += 1\n",
"\n",
"with capture.capture_output() as cap:\n",
" !cd ~/.insightface/models && unzip -o buffalo_l.zip -d buffalo_l\n",
"\n",
"\n",
"clear_output()\n",
"# clear_output()\n",
"inf('\\u2714 Done','success', '50px')"
]
},
@ -170,7 +174,7 @@
"target_path = '/content/gdrive/MyDrive/example/vid.mp4' #@param {type:\"string\"}\n",
"path_to_output = '/content/gdrive/MyDrive/roop_output/out_vid.mp4' #@param {type:\"string\"}\n",
"keep_fps = True #@param {type:\"boolean\"}\n",
"keep_frames = True #@param {type:\"boolean\"}\n",
"keep_frames = False #@param {type:\"boolean\"}\n",
"\n",
"kframes = \"--keep-frames\" if keep_frames else \"\"\n",
"kfps = \"--keep-fps\" if keep_fps else \"\"\n",