Spaces:
Sleeping
Sleeping
File size: 1,991 Bytes
76d118b |
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 |
import os
import sys
import subprocess
import gdown
import shutil
import nltk
from pathlib import Path
# Install NLTK data
nltk.download('punkt')
# Create directories
os.makedirs('DF-GAN/code/models', exist_ok=True)
os.makedirs('data', exist_ok=True)
# Clone the DF-GAN repository
if not os.path.exists('DF-GAN/.git'):
print("Cloning DF-GAN repository...")
subprocess.run(["git", "clone", "https://github.com/tobran/DF-GAN.git", "DF-GAN_temp"])
# Move only necessary files to avoid duplicates
shutil.copytree('DF-GAN_temp/code/models', 'DF-GAN/code/models', dirs_exist_ok=True)
shutil.copytree('DF-GAN_temp/code/lib', 'DF-GAN/code/lib', dirs_exist_ok=True)
# Clean up
shutil.rmtree('DF-GAN_temp')
print("Repository cloned and organized.")
# Download model files
# DF-GAN pretrained bird model
bird_model_url = 'https://drive.google.com/uc?id=1rzfcCvGwU8vLCrn5reWxmrAMms6WQGA6'
bird_model_path = 'data/state_epoch_1220.pth'
# Text encoder for birds
text_encoder_url = 'https://drive.google.com/uc?id=1xwIyLPYtYn9YGPIcRuWXxaxcw_oPGQK4'
text_encoder_path = 'data/text_encoder200.pth'
# Captions DAMSM pickle file
captions_pickle_url = 'https://drive.google.com/uc?id=1FfNMRpOZGaO3mKYyj2VDVEW1ChZ12lJp'
captions_pickle_path = 'data/captions_DAMSM.pickle'
# Download if files don't exist
if not os.path.exists(bird_model_path):
print(f"Downloading bird model to {bird_model_path}...")
gdown.download(bird_model_url, bird_model_path, quiet=False)
if not os.path.exists(text_encoder_path):
print(f"Downloading text encoder to {text_encoder_path}...")
gdown.download(text_encoder_url, text_encoder_path, quiet=False)
if not os.path.exists(captions_pickle_path):
print(f"Downloading captions pickle to {captions_pickle_path}...")
gdown.download(captions_pickle_url, captions_pickle_path, quiet=False)
print("All model files downloaded and prepared successfully!") |