forked from TNTwise/REAL-Video-Enhancer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcases.py
95 lines (75 loc) · 2.63 KB
/
testcases.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from src.ModelHandler import (
ncnnInterpolateModels,
pytorchInterpolateModels,
ncnnUpscaleModels,
pytorchUpscaleModels,
tensorrtInterpolateModels,
tensorrtUpscaleModels,
)
import requests
import os
import tarfile
MODEL_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "models")
def removeFile(file):
try:
os.remove(file)
except Exception:
print("Failed to remove file!")
def extractTarGZ(file):
"""
Extracts a tar gz in the same directory as the tar file and deleted it after extraction.
"""
origCWD = os.getcwd()
dir_path = os.path.dirname(os.path.realpath(file))
os.chdir(dir_path)
print("Extracting: " + file)
tar = tarfile.open(file, "r:gz")
tar.extractall()
tar.close()
removeFile(file)
os.chdir(origCWD)
def download_file(url, download_path):
"""
Downloads a file from the given URL and saves it to the specified path.
:param url: The URL of the file to download.
:param download_path: The path where the file should be saved.
"""
try:
# Send a GET request to the URL
response = requests.get(url, stream=True)
response.raise_for_status() # Check if the request was successful
# Open the file in write-binary mode and write the content
with open(download_path, "wb") as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
print(f"File downloaded successfully: {download_path}")
except requests.exceptions.RequestException as e:
print(f"Failed to download file: {e}")
def downloadModel(modelFile, downloadModelPath: str = None):
url = (
"https://github.com/TNTwise/real-video-enhancer-models/releases/download/models/"
+ modelFile
)
model_on_filesystem = os.path.join(downloadModelPath, modelFile)
if os.path.isfile(model_on_filesystem) or os.path.exists(
model_on_filesystem.replace(".tar.gz", "")
):
return
download_file(url, model_on_filesystem)
print("Done")
if "tar.gz" in modelFile:
print("Extracting File")
extractTarGZ(model_on_filesystem)
def downloadModelsFromModelList(model_list: list):
for model in model_list:
downloadModel(modelFile=model_list[model][1], downloadModelPath=MODEL_PATH)
def downloadModels():
downloadModelsFromModelList(ncnnInterpolateModels)
downloadModelsFromModelList(pytorchInterpolateModels)
downloadModelsFromModelList(ncnnUpscaleModels)
downloadModelsFromModelList(pytorchUpscaleModels)
def main():
downloadModels()
# render video
if __name__ == "__main__":
main()