Spaces:
Runtime error
Runtime error
Update app.py
Browse files188 unmodified lines18919019119219319419519619719819920020120216 unmodified lines21922022122222322410 unmodified lines23523623723823924015 unmodified lines256257258259260261188 unmodified linesimport requestsimport ioimport warningswarnings.filterwarnings("ignore")device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')# Load pretrained StyleGAN modelmodel_path = 'https://drive.google.com/file/d/12_fsSQgUfOCAPQaDtq2QPCLE74qTQEwt/view?usp=sharing'with open(model_path, 'rb') as f:G = legacy.load_network_pkl(f)['G_ema'].to(device)# # Style mixing between two projected images# def mix_styles(image1_path, image2_path, styles_to_mix):16 unmodified lines# mixed_image = Image.fromarray(image[0], 'RGB')# return mixed_image# ----------- UTIL: ENSURE PROJECTION ----------def ensure_projection(image_path):image_name = os.path.splitext(os.path.basename(image_path))[0]proj_dir = os.path.join("projection_results", image_name)10 unmodified lines], check=True)return proj_filedef mix_styles(image1_path, image2_path, styles_to_mix):proj_file1 = ensure_projection(image1_path)proj_file2 = ensure_projection(image2_path)15 unmodified linesreturn mixed_image# Handles style mixing + output bufferdef style_mixing_interface(image1, image2, mix_value):if image1 is None or image2 is None:188 unmodified lines18919019119219319419519619719819920020120220316 unmodified lines22022122222322422522622722822923023123223323423523623723823924024124224324424524624710 unmodified lines25825926026126226326415 unmodified lines280281282283284285286188 unmodified linesimport requestsimport ioimport warningsimport gdownwarnings.filterwarnings("ignore")# device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')# # Load pretrained StyleGAN model# model_path = 'https://drive.google.com/file/d/12_fsSQgUfOCAPQaDtq2QPCLE74qTQEwt/view?usp=sharing'# with open(model_path, 'rb') as f:# G = legacy.load_network_pkl(f)['G_ema'].to(device)# # Style mixing between two projected images# def mix_styles(image1_path, image2_path, styles_to_mix):16 unmodified lines# mixed_image = Image.fromarray(image[0], 'RGB')# return mixed_image# ----------- UTIL: ENSURE PROJECTION ----------# -------- CONFIGURATION --------device = torch.device("cuda" if torch.cuda.is_available() else "cpu")# Google Drive model setupfile_id = "12_fsSQgUfOCAPQaDtq2QPCLE74qTQEwt" # from your shared linkoutput_path = "dress_model.pkl"# Download the model if it's not presentif not os.path.exists(output_path):print("Downloading StyleGAN2 model from Google Drive...")gdown.download(f"https://drive.google.com/uc?id={file_id}", output_path, quiet=False)# Load the modelwith open(output_path, 'rb') as f:G = legacy.load_network_pkl(f)['G_ema'].to(device)# Save model path for projector.pyNETWORK_PKL = output_path# -------- ENSURE PROJECTION --------def ensure_projection(image_path):image_name = os.path.splitext(os.path.basename(image_path))[0]proj_dir = os.path.join("projection_results", image_name)10 unmodified lines], check=True)return proj_file# -------- STYLE MIXING --------def mix_styles(image1_path, image2_path, styles_to_mix):proj_file1 = ensure_projection(image1_path)proj_file2 = ensure_projection(image2_path)15 unmodified linesreturn mixed_image# Handles style mixing + output bufferdef style_mixing_interface(image1, image2, mix_value):if image1 is None or image2 is None:
app.py+30-5