Skip to content

Commit 720f8fb

Browse files
committed
adds automatic downloads of AI models
1 parent 7f171b1 commit 720f8fb

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,4 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
AI/*

RealScaler.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
# Standard library imports
3+
import os
34
import sys
45
from shutil import rmtree as remove_directory
56
from timeit import default_timer as timer
@@ -134,6 +135,8 @@
134135
githubme = "https://github.com/Djdefrag/ReSRScaler"
135136
telegramme = "https://linktr.ee/j3ngystudio"
136137

138+
# Remote URL where the AI *.pth assets can be downloaded from.
139+
REMOTE_AI_URL = "https://zackees.github.io/ai-image-video-models"
137140

138141
# SRVGGNetCompact
139142
SRVGGNetCompact_vram_multiplier = 1.7
@@ -190,6 +193,14 @@
190193
]
191194

192195

196+
def ensure_downloaded(modelfile: str, outpath: str) -> None:
197+
"""Download a model file if it doesn't exist."""
198+
if os.path.exists(outpath):
199+
return # Already downloaded
200+
asset_url = f"{REMOTE_AI_URL}/{modelfile}"
201+
from download import download # Lazy import
202+
download(asset_url, outpath)
203+
193204

194205
# AI models -------------------
195206

@@ -202,7 +213,9 @@ def load_AI_model(
202213
) -> any:
203214

204215
write_process_status(processing_queue, f"Loading AI model")
205-
model_path = find_by_relative_path(f"AI{os_separator}{selected_AI_model}.pth")
216+
model_file = f"{selected_AI_model}.pth"
217+
model_path = find_by_relative_path(f"AI{os_separator}{model_file}")
218+
ensure_downloaded(model_file, model_path)
206219

207220
if selected_AI_model == 'RealESRGANx4':
208221
model = RealESRGAN_Net()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ packaging
99
moviepy
1010
opencv-python-headless
1111
nuitka
12+
download

0 commit comments

Comments
 (0)