fix: 🔥 various preparing for the first tag

This commit is contained in:
melMass
2023-06-27 20:49:37 +02:00
parent afd0843145
commit 793784a5fd
17 changed files with 994 additions and 228 deletions
+148
View File
@@ -0,0 +1,148 @@
import os
import requests
from rich.console import Console
from tqdm import tqdm
try:
import folder_paths
except ModuleNotFoundError:
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "../../.."))
import folder_paths
models_to_download = {
"DeepBump": {
"size": 25.5,
"download_url": "https://github.com/HugoTini/DeepBump/raw/master/deepbump256.onnx",
"destination": "deepbump",
},
"Roop": {
"size": 660,
"download_url": [
"https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_mobilenet0.25_Final.pth",
"https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth",
"https://huggingface.co/deepinsight/inswapper/resolve/main/inswapper_128.onnx",
],
"destination": "roop",
},
}
console = Console()
from urllib.parse import urlparse
from pathlib import Path
def download_model(download_url, destination):
if isinstance(download_url, list):
for url in download_url:
download_model(url, destination)
return
filename = os.path.basename(urlparse(download_url).path)
response = requests.get(download_url, stream=True)
total_size = int(response.headers.get("content-length", 0))
destination_path = os.path.join(destination, filename)
with open(destination_path, "wb") as file:
with tqdm(
total=total_size, unit="B", unit_scale=True, desc=destination_path, ncols=80
) as progress_bar:
for data in response.iter_content(chunk_size=4096):
file.write(data)
progress_bar.update(len(data))
console.print(
f"Downloaded model from {download_url} to {destination_path}",
style="bold green",
)
def ask_user_for_downloads(models_to_download):
console.print("Choose models to download:")
choices = {}
for i, model_name in enumerate(models_to_download.keys(), start=1):
choices[str(i)] = model_name
console.print(f"{i}. {model_name}")
console.print(
"Enter the numbers of the models you want to download (comma-separated):"
)
user_input = console.input(">> ")
selected_models = user_input.split(",")
models_to_download_selected = {}
for choice in selected_models:
choice = choice.strip()
if choice in choices:
model_name = choices[choice]
models_to_download_selected[model_name] = models_to_download[model_name]
elif choice == "":
# download all
models_to_download_selected = models_to_download
else:
console.print(f"Invalid choice: {choice}. Skipping.")
return models_to_download_selected
def handle_interrupt():
console.print("Interrupted by user.", style="bold red")
def main(models_to_download):
try:
models_to_download_selected = {}
def check_destination(urls, destination):
if isinstance(urls, list):
for url in urls:
check_destination(url, destination)
return
filename = os.path.basename(urlparse(urls).path)
destination = os.path.join(folder_paths.models_dir, destination)
if not os.path.exists(destination):
os.makedirs(destination)
destination_path = os.path.join(destination, filename)
if os.path.exists(destination_path):
url_name = os.path.basename(urlparse(urls).path)
console.print(
f"Checkpoint '{url_name}' for {model_name} already exists in '{destination}'"
)
else:
model_details["destination"] = destination
models_to_download_selected[model_name] = model_details
for model_name, model_details in models_to_download.items():
destination = model_details["destination"]
download_url = model_details["download_url"]
check_destination(download_url, destination)
if not models_to_download_selected:
console.print("No new models to download.")
return
models_to_download_selected = ask_user_for_downloads(
models_to_download_selected
)
for model_name, model_details in models_to_download_selected.items():
download_url = model_details["download_url"]
destination = model_details["destination"]
download_model(download_url, destination)
except KeyboardInterrupt:
handle_interrupt()
if __name__ == "__main__":
main(models_to_download)
+93
View File
@@ -0,0 +1,93 @@
import os
import ast
import json
import sys
from rich.console import Console
from rich.table import Table
from rich.progress import Progress
console = Console(stderr=True)
def get_imported_modules(filename):
with open(filename, "r") as file:
tree = ast.parse(file.read())
imported_modules = []
for node in ast.walk(tree):
if isinstance(node, ast.Import):
imported_modules.extend(
(alias.name, alias.name in sys.builtin_module_names)
for alias in node.names
)
elif isinstance(node, ast.ImportFrom):
if node.module:
imported_modules.append(
(node.module, node.module in sys.builtin_module_names)
)
return imported_modules
def list_imported_modules(folder):
modules = []
file_count = sum(len(files) for _, _, files in os.walk(folder))
progress = Progress()
task = progress.add_task("[cyan]Scanning files...", total=file_count)
for root, _, files in os.walk(folder):
for file in files:
if file.endswith(".py"):
file_path = os.path.join(root, file)
imported_modules = get_imported_modules(file_path)
modules.extend(imported_modules)
progress.update(task, advance=1)
progress.stop()
return modules
if __name__ == "__main__":
if len(sys.argv) < 2:
console.print(
"[bold red]Please provide the folder path as a command-line argument.[/bold red]"
)
sys.exit(1)
# folder_path = input("Enter the folder path: ")
# while not os.path.isdir(folder_path):
# console.print("[bold red]Invalid folder path![/bold red]")
# folder_path = input("Enter the folder path: ")
folder_path = sys.argv[1]
if not os.path.isdir(folder_path):
console.print("[bold red]Invalid folder path![/bold red]")
sys.exit(1)
console.print("[bold green]=== Python Imported Modules ===[/bold green]\n")
console.print(f"Scanning folder: [bold]{folder_path}[/bold]\n")
imported_modules = list_imported_modules(folder_path)
console.print(f"\n[bold green]Imported Modules:[/bold green]\n")
table = Table(show_header=True, header_style="bold cyan")
table.add_column("Module")
table.add_column("Type")
for module, is_builtin in imported_modules:
module_type = "Built-in" if is_builtin else "External"
table.add_row(module, module_type)
console.print(table)
json_data = json.dumps(
[
{"module": module, "type": "Built-in" if is_builtin else "External"}
for module, is_builtin in imported_modules
],
indent=4,
)
print(json_data)