Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -189,14 +189,15 @@ import torch_utils
|
|
| 189 |
import requests
|
| 190 |
import io
|
| 191 |
import warnings
|
|
|
|
| 192 |
|
| 193 |
warnings.filterwarnings("ignore")
|
| 194 |
-
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 195 |
|
| 196 |
-
# Load pretrained StyleGAN model
|
| 197 |
-
model_path = 'https://drive.google.com/file/d/12_fsSQgUfOCAPQaDtq2QPCLE74qTQEwt/view?usp=sharing'
|
| 198 |
-
with open(model_path, 'rb') as f:
|
| 199 |
-
|
| 200 |
|
| 201 |
# # Style mixing between two projected images
|
| 202 |
# def mix_styles(image1_path, image2_path, styles_to_mix):
|
|
@@ -219,6 +220,28 @@ with open(model_path, 'rb') as f:
|
|
| 219 |
# mixed_image = Image.fromarray(image[0], 'RGB')
|
| 220 |
# return mixed_image
|
| 221 |
# ----------- UTIL: ENSURE PROJECTION ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
def ensure_projection(image_path):
|
| 223 |
image_name = os.path.splitext(os.path.basename(image_path))[0]
|
| 224 |
proj_dir = os.path.join("projection_results", image_name)
|
|
@@ -235,6 +258,7 @@ def ensure_projection(image_path):
|
|
| 235 |
], check=True)
|
| 236 |
return proj_file
|
| 237 |
|
|
|
|
| 238 |
def mix_styles(image1_path, image2_path, styles_to_mix):
|
| 239 |
proj_file1 = ensure_projection(image1_path)
|
| 240 |
proj_file2 = ensure_projection(image2_path)
|
|
@@ -256,6 +280,7 @@ def mix_styles(image1_path, image2_path, styles_to_mix):
|
|
| 256 |
return mixed_image
|
| 257 |
|
| 258 |
|
|
|
|
| 259 |
# Handles style mixing + output buffer
|
| 260 |
def style_mixing_interface(image1, image2, mix_value):
|
| 261 |
if image1 is None or image2 is None:
|
|
|
|
| 189 |
import requests
|
| 190 |
import io
|
| 191 |
import warnings
|
| 192 |
+
import gdown
|
| 193 |
|
| 194 |
warnings.filterwarnings("ignore")
|
| 195 |
+
# device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 196 |
|
| 197 |
+
# # Load pretrained StyleGAN model
|
| 198 |
+
# model_path = 'https://drive.google.com/file/d/12_fsSQgUfOCAPQaDtq2QPCLE74qTQEwt/view?usp=sharing'
|
| 199 |
+
# with open(model_path, 'rb') as f:
|
| 200 |
+
# G = legacy.load_network_pkl(f)['G_ema'].to(device)
|
| 201 |
|
| 202 |
# # Style mixing between two projected images
|
| 203 |
# def mix_styles(image1_path, image2_path, styles_to_mix):
|
|
|
|
| 220 |
# mixed_image = Image.fromarray(image[0], 'RGB')
|
| 221 |
# return mixed_image
|
| 222 |
# ----------- UTIL: ENSURE PROJECTION ----------
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
# -------- CONFIGURATION --------
|
| 226 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 227 |
+
|
| 228 |
+
# Google Drive model setup
|
| 229 |
+
file_id = "12_fsSQgUfOCAPQaDtq2QPCLE74qTQEwt" # from your shared link
|
| 230 |
+
output_path = "dress_model.pkl"
|
| 231 |
+
|
| 232 |
+
# Download the model if it's not present
|
| 233 |
+
if not os.path.exists(output_path):
|
| 234 |
+
print("Downloading StyleGAN2 model from Google Drive...")
|
| 235 |
+
gdown.download(f"https://drive.google.com/uc?id={file_id}", output_path, quiet=False)
|
| 236 |
+
|
| 237 |
+
# Load the model
|
| 238 |
+
with open(output_path, 'rb') as f:
|
| 239 |
+
G = legacy.load_network_pkl(f)['G_ema'].to(device)
|
| 240 |
+
|
| 241 |
+
# Save model path for projector.py
|
| 242 |
+
NETWORK_PKL = output_path
|
| 243 |
+
|
| 244 |
+
# -------- ENSURE PROJECTION --------
|
| 245 |
def ensure_projection(image_path):
|
| 246 |
image_name = os.path.splitext(os.path.basename(image_path))[0]
|
| 247 |
proj_dir = os.path.join("projection_results", image_name)
|
|
|
|
| 258 |
], check=True)
|
| 259 |
return proj_file
|
| 260 |
|
| 261 |
+
# -------- STYLE MIXING --------
|
| 262 |
def mix_styles(image1_path, image2_path, styles_to_mix):
|
| 263 |
proj_file1 = ensure_projection(image1_path)
|
| 264 |
proj_file2 = ensure_projection(image2_path)
|
|
|
|
| 280 |
return mixed_image
|
| 281 |
|
| 282 |
|
| 283 |
+
|
| 284 |
# Handles style mixing + output buffer
|
| 285 |
def style_mixing_interface(image1, image2, mix_value):
|
| 286 |
if image1 is None or image2 is None:
|