Skip to content

Commit

Permalink
use alive_bar instead of tqdm
Browse files Browse the repository at this point in the history
  • Loading branch information
NevermindNilas committed Jun 17, 2024
1 parent 6e3873b commit a4a498f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 61 deletions.
38 changes: 11 additions & 27 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import sys
import logging


from tqdm import tqdm
from alive_progress import alive_bar
from concurrent.futures import ThreadPoolExecutor
from src.argumentsChecker import argumentChecker
from src.getVideoMetadata import getVideoMetadata
Expand Down Expand Up @@ -144,8 +143,6 @@ def processFrame(self, frame):
if self.dedup:
if self.dedup_process.run(frame):
self.dedupCount += 1
self.pbar.total -= 1
self.pbar.refresh()
return

if self.denoise:
Expand All @@ -160,40 +157,27 @@ def processFrame(self, frame):
)

self.writeBuffer.write(frame)
if self.interpolate:
self.pbar.update(self.interpolate_factor)
else:
self.pbar.update(1)

except Exception as e:
logging.exception(f"Something went wrong while processing the frames, {e}")

def process(self):
frameCount = 0
self.dedupCount = 0
while True:
frame = self.readBuffer.read()
if frame is None:
break
self.processFrame(frame)
frameCount += 1

increment = 1 if not self.interpolate else self.interpolate_factor
with alive_bar(self.totalFrames * increment, title='Processing', bar='smooth', unit='frames') as bar:
for _ in range(self.totalFrames):
frame = self.readBuffer.read()
self.processFrame(frame)
frameCount += 1
bar(increment)

logging.info(f"Processed {frameCount} frames")
if self.dedupCount > 0:
logging.info(f"Deduplicated {self.dedupCount} frames")

self.writeBuffer.close()

def start(self):
self.pbar = tqdm(
total=self.totalFrames * self.interpolate_factor if self.interpolate else self.totalFrames,
unit="frames",
unit_scale=True,
colour="green",
desc="🎥 Processing Frames",
bar_format="{l_bar}{bar}|{n_fmt}/{total_fmt} [ETA: {remaining}, {rate_fmt}]",
)

try:
(
self.new_width,
Expand Down Expand Up @@ -237,7 +221,7 @@ def start(self):
audio=self.audio,
benchmark=self.benchmark,
)

with ThreadPoolExecutor(max_workers=3) as executor:
executor.submit(self.readBuffer.start)
executor.submit(self.process)
Expand Down
2 changes: 1 addition & 1 deletion requirements-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GPUtil
spandrel
yt-dlp
requests
tqdm
alive-progress
tensorrt
scikit-image
scenedetect[opencv]
Expand Down
2 changes: 1 addition & 1 deletion requirements-windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ wmi
spandrel
yt-dlp
requests
tqdm
alive-progress
tensorrt
tensorrt_cu12
scikit-image
Expand Down
16 changes: 6 additions & 10 deletions src/downloadModels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import logging
import requests
from tqdm import tqdm
from alive_progress import alive_bar

dirPath = os.path.dirname(__file__)
weightsDir = os.path.join(dirPath, "weights")
Expand Down Expand Up @@ -363,15 +363,11 @@ def downloadAndLog(model: str, filename: str, download_url: str, folderPath: str
total_size_in_bytes = None
logging.error(e)

progress_bar = tqdm(
total=total_size_in_bytes, unit="iB", unit_scale=True, colour="green"
)

with open(os.path.join(folderPath, filename), "wb") as file:
for data in response.iter_content(chunk_size=1024):
progress_bar.update(len(data))
file.write(data)
progress_bar.close()
with alive_bar(total_size_in_bytes, title="Progress", bar="smooth") as bar:
with open(os.path.join(folderPath, filename), "wb") as file:
for data in response.iter_content(chunk_size=1024):
file.write(data)
bar(len(data))

if filename.endswith(".zip"):
import zipfile
Expand Down
1 change: 0 additions & 1 deletion src/ffmpegSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import subprocess
import numpy as np
import os
import sys
import shutil
import torch
import decord
Expand Down
8 changes: 3 additions & 5 deletions src/getFFMPEG.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import zipfile
import tarfile
import logging
from tqdm import tqdm
from alive_progress import alive_bar
from pathlib import Path
import platform

Expand Down Expand Up @@ -53,12 +53,10 @@ def downloadAndExtractFFMPEG(ffmpegPath):
response = requests.get(FFMPEGURL, stream=True)
totalSizeInBytes = int(response.headers.get("content-length", 0))

with tqdm(
total=totalSizeInBytes, unit="iB", unit_scale=True, colour="green"
) as progress_bar, open(ffmpegArchivePath, "wb") as file:
with alive_bar(total=totalSizeInBytes, title="Downloading FFMPEG", bar="smooth") as bar, open(ffmpegArchivePath, "wb") as file:
for data in response.iter_content(chunk_size=1024):
progress_bar.update(len(data))
file.write(data)
bar(len(data))

extractFunc(ffmpegArchivePath, ffmpegDir)

Expand Down
26 changes: 10 additions & 16 deletions src/updateScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import logging
import json
import pathlib
from tqdm import tqdm
from alive_progress import alive_bar
import subprocess
import os
import shutil

from .coloredPrints import green

Expand Down Expand Up @@ -56,21 +55,16 @@ def updateScript(scriptVersion, mainPath):
totalSizeInBytes = int(
response.headers.get("content-length", 0)
)
blockSize = 1024
progressBar = tqdm(

with alive_bar(
total=totalSizeInBytes,
unit="iB",
unit_scale=True,
bar_format="{l_bar}%s{bar}%s{r_bar}"
% ("\033[32m", "\033[0m"),
)
with open(filePath, "wb") as file:
for data in response.iter_content(blockSize):
progressBar.update(len(data))
title="Downloading",
bar="smooth",
length=30,
) as bar, open(filePath, "wb") as file:
for data in response.iter_content(1024):
file.write(data)
progressBar.close()
if totalSizeInBytes != 0 and progressBar.n != totalSizeInBytes:
print("ERROR, something went wrong")
bar(len(data))

logging.info(
"Download complete, extracting files, depending on the size of the update this might take a while"
Expand All @@ -96,7 +90,7 @@ def updateScript(scriptVersion, mainPath):

filePath.unlink()
break

"""
TO:DO - WIP, need to fix this
answer = input("Do you wish to copy over the models and ffmpeg files to the new directory? (y/n): ")
Expand Down

0 comments on commit a4a498f

Please sign in to comment.