Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -242,6 +242,13 @@ def ensure_case_generated(case_id: str) -> Dict[str, Any]:
|
|
| 242 |
if existing_public:
|
| 243 |
return existing_public
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
# Ensure we have at least some IA records; if not, auto-ingest a default set (one page)
|
| 246 |
pool = ia_pool_ref().get() or {}
|
| 247 |
if not pool:
|
|
@@ -272,7 +279,9 @@ def ensure_case_generated(case_id: str) -> Dict[str, Any]:
|
|
| 272 |
style_period = "sourced from Internet Archive; museum catalog reproduction"
|
| 273 |
|
| 274 |
# Download authentic image
|
| 275 |
-
|
|
|
|
|
|
|
| 276 |
|
| 277 |
images_urls: List[str] = []
|
| 278 |
signature_crops: List[str] = []
|
|
@@ -712,4 +721,11 @@ def leaderboard_daily():
|
|
| 712 |
# 6) MAIN
|
| 713 |
# -----------------------------------------------------------------------------
|
| 714 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 715 |
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", "7860")), debug=True)
|
|
|
|
|
|
| 242 |
if existing_public:
|
| 243 |
return existing_public
|
| 244 |
|
| 245 |
+
# Make sure we have a minimum pool of cached images ready
|
| 246 |
+
try:
|
| 247 |
+
ensure_minimum_ia_pool()
|
| 248 |
+
except Exception as e:
|
| 249 |
+
print("Bootstrap warning:", e)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
# Ensure we have at least some IA records; if not, auto-ingest a default set (one page)
|
| 253 |
pool = ia_pool_ref().get() or {}
|
| 254 |
if not pool:
|
|
|
|
| 279 |
style_period = "sourced from Internet Archive; museum catalog reproduction"
|
| 280 |
|
| 281 |
# Download authentic image
|
| 282 |
+
source_url = ia_item.get("storage_url") or ia_item["download_url"]
|
| 283 |
+
auth_img = download_image_to_pil(source_url)
|
| 284 |
+
|
| 285 |
|
| 286 |
images_urls: List[str] = []
|
| 287 |
signature_crops: List[str] = []
|
|
|
|
| 721 |
# 6) MAIN
|
| 722 |
# -----------------------------------------------------------------------------
|
| 723 |
if __name__ == "__main__":
|
| 724 |
+
# Optional: pre-warm pool on boot so you’re ready before first request
|
| 725 |
+
if os.environ.get("BOOTSTRAP_IA", "1") == "1":
|
| 726 |
+
print("Bootstrapping Internet Archive pool...")
|
| 727 |
+
stats = ensure_minimum_ia_pool()
|
| 728 |
+
print("Bootstrap complete:", stats)
|
| 729 |
+
|
| 730 |
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", "7860")), debug=True)
|
| 731 |
+
|