Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update download_models.py (lots of bugfixes) #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 52 additions & 24 deletions gradio_demo/download_models.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
from huggingface_hub import hf_hub_download
import gdown
import os
import gdown
import zipfile

# download models
hf_hub_download(
repo_id="InstantX/InstantID",
filename="ControlNetModel/config.json",
local_dir="./checkpoints",
)
hf_hub_download(
repo_id="InstantX/InstantID",
filename="ControlNetModel/diffusion_pytorch_model.safetensors",
local_dir="./checkpoints",
)
hf_hub_download(
repo_id="InstantX/InstantID", filename="ip-adapter.bin", local_dir="./checkpoints"
)
hf_hub_download(
repo_id="latent-consistency/lcm-lora-sdxl",
filename="pytorch_lora_weights.safetensors",
local_dir="./checkpoints",
def download_and_extract(url, output_dir, zip_file_name):
"""
Downloads a zip file from the specified URL and extracts it to the given directory.

Parameters:
url (str): The URL from which to download the zip file.
output_dir (str): The directory where the zip file will be saved and extracted.
zip_file_name (str): The name of the zip file to be downloaded.

This function performs several tasks:
- Ensures the output directory exists.
- Downloads the zip file using gdown if it does not already exist.
- Extracts the zip file into the specified directory.
"""

# Ensure the output directory exists
if not os.path.exists(output_dir):
os.makedirs(output_dir)
print(f"Created directory: {output_dir}")

# Full path for the downloaded zip file
zip_path = os.path.join(output_dir, zip_file_name)

# Check if the zip file already exists
if not os.path.exists(zip_path):
# Download the file
try:
print(f"Downloading file to: {zip_path}")
gdown.download(url=url, output=zip_path, quiet=False, fuzzy=True)
print("Download complete.")
except Exception as e:
print(f"Failed to download the file: {e}")
return # Exit if download fails
else:
print(f"File already exists: {zip_path}")

# Extract the zip file
try:
print(f"Extracting file to: {output_dir}")
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(output_dir)
print("File extracted successfully.")
except Exception as e:
print(f"Failed to extract the file: {e}")

# Example usage
download_and_extract(
url="https://drive.google.com/uc?id=18wEUfMNohBJ4K3Ly5wpTejPfDzp-8fI8",
output_dir="./models",
zip_file_name="antelopev2.zip"
)
# download antelopev2
gdown.download(url="https://drive.google.com/file/d/18wEUfMNohBJ4K3Ly5wpTejPfDzp-8fI8/view?usp=sharing", output="./models/", quiet=False, fuzzy=True)
# unzip antelopev2.zip
os.system("unzip ./models/antelopev2.zip -d ./models/")