Spaces:
Sleeping
Sleeping
Commit
·
07eb20a
1
Parent(s):
138df91
Improve debugging with better error handling and file size info
Browse files
app.py
CHANGED
|
@@ -34,34 +34,52 @@ def ensure_weights():
|
|
| 34 |
"pretrained_models/sfe_editor_light.pt",
|
| 35 |
"pretrained_models/stylegan2-ffhq-config-f.pt",
|
| 36 |
]
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
return
|
| 39 |
|
| 40 |
repo_id = "LogicGoInfotechSpaces/Smile_Changer_pre_model"
|
| 41 |
logger.info("Missing weights; downloading snapshot from %s", repo_id)
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Add a small delay to ensure files are fully written
|
| 51 |
import time
|
| 52 |
-
time.sleep(
|
| 53 |
|
| 54 |
# Debug: List all files in pretrained_models directory
|
| 55 |
if os.path.exists("pretrained_models"):
|
| 56 |
logger.info("Files in pretrained_models directory:")
|
| 57 |
-
|
| 58 |
-
for
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# Verify critical files exist
|
| 62 |
for file_path in need:
|
| 63 |
if not os.path.exists(file_path):
|
| 64 |
logger.warning("File %s still not found after download", file_path)
|
|
|
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
def get_runner() -> SimpleRunner:
|
|
|
|
| 34 |
"pretrained_models/sfe_editor_light.pt",
|
| 35 |
"pretrained_models/stylegan2-ffhq-config-f.pt",
|
| 36 |
]
|
| 37 |
+
|
| 38 |
+
# Check if any of the needed files exist
|
| 39 |
+
files_exist = any(os.path.exists(p) for p in need)
|
| 40 |
+
if files_exist:
|
| 41 |
+
logger.info("Some weights already exist, skipping download")
|
| 42 |
return
|
| 43 |
|
| 44 |
repo_id = "LogicGoInfotechSpaces/Smile_Changer_pre_model"
|
| 45 |
logger.info("Missing weights; downloading snapshot from %s", repo_id)
|
| 46 |
+
|
| 47 |
+
try:
|
| 48 |
+
snapshot_download(
|
| 49 |
+
repo_id=repo_id,
|
| 50 |
+
local_dir="pretrained_models",
|
| 51 |
+
local_dir_use_symlinks=False,
|
| 52 |
+
allow_patterns=["**/*"],
|
| 53 |
+
token=os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN"),
|
| 54 |
+
)
|
| 55 |
+
logger.info("Download completed successfully")
|
| 56 |
+
except Exception as e:
|
| 57 |
+
logger.error("Download failed: %s", e)
|
| 58 |
+
return
|
| 59 |
|
| 60 |
# Add a small delay to ensure files are fully written
|
| 61 |
import time
|
| 62 |
+
time.sleep(3)
|
| 63 |
|
| 64 |
# Debug: List all files in pretrained_models directory
|
| 65 |
if os.path.exists("pretrained_models"):
|
| 66 |
logger.info("Files in pretrained_models directory:")
|
| 67 |
+
try:
|
| 68 |
+
for root, dirs, files in os.walk("pretrained_models"):
|
| 69 |
+
for file in files:
|
| 70 |
+
full_path = os.path.join(root, file)
|
| 71 |
+
logger.info(" %s (size: %d bytes)", full_path, os.path.getsize(full_path))
|
| 72 |
+
except Exception as e:
|
| 73 |
+
logger.error("Error listing files: %s", e)
|
| 74 |
+
else:
|
| 75 |
+
logger.error("pretrained_models directory does not exist!")
|
| 76 |
|
| 77 |
# Verify critical files exist
|
| 78 |
for file_path in need:
|
| 79 |
if not os.path.exists(file_path):
|
| 80 |
logger.warning("File %s still not found after download", file_path)
|
| 81 |
+
else:
|
| 82 |
+
logger.info("File %s found successfully", file_path)
|
| 83 |
|
| 84 |
|
| 85 |
def get_runner() -> SimpleRunner:
|