update
Browse files- backend_deploy.py +37 -40
- frontend/src/app/page.tsx +3 -3
backend_deploy.py
CHANGED
|
@@ -461,52 +461,49 @@ def deploy_to_huggingface_space(
|
|
| 461 |
# Don't create README - HuggingFace will auto-generate it
|
| 462 |
# We'll add the anycoder tag after deployment
|
| 463 |
|
| 464 |
-
#
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
api.create_repo(
|
| 489 |
-
repo_id=repo_id,
|
| 490 |
-
repo_type="space",
|
| 491 |
-
space_sdk=sdk,
|
| 492 |
-
private=private,
|
| 493 |
-
exist_ok=False
|
| 494 |
-
)
|
| 495 |
-
else:
|
| 496 |
-
# For other languages, create space normally
|
| 497 |
api.create_repo(
|
| 498 |
repo_id=repo_id,
|
| 499 |
repo_type="space",
|
| 500 |
space_sdk=sdk,
|
| 501 |
private=private,
|
| 502 |
-
exist_ok=
|
| 503 |
)
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
|
| 511 |
# Upload files
|
| 512 |
if not commit_message:
|
|
|
|
| 461 |
# Don't create README - HuggingFace will auto-generate it
|
| 462 |
# We'll add the anycoder tag after deployment
|
| 463 |
|
| 464 |
+
# ALWAYS create/ensure repo exists (with exist_ok=True)
|
| 465 |
+
# This works for both new spaces and updates!
|
| 466 |
+
try:
|
| 467 |
+
if language == "transformers.js" and not is_update:
|
| 468 |
+
# For NEW transformers.js spaces, try to duplicate the template
|
| 469 |
+
print(f"[Deploy] Creating new transformers.js space: {repo_id}")
|
| 470 |
+
try:
|
| 471 |
+
from huggingface_hub import duplicate_space
|
| 472 |
+
|
| 473 |
+
# IMPORTANT: duplicate_space expects just the space name, not the full repo_id
|
| 474 |
+
# It will automatically prepend the username
|
| 475 |
+
print(f"[Deploy] Attempting to duplicate template space to: {space_name}")
|
| 476 |
+
result = duplicate_space(
|
| 477 |
+
from_id="static-templates/transformers.js",
|
| 478 |
+
to_id=space_name, # Just the space name, not username/space-name
|
| 479 |
+
token=token,
|
| 480 |
+
exist_ok=True
|
| 481 |
+
)
|
| 482 |
+
print(f"[Deploy] Template duplication result: {result}")
|
| 483 |
+
except Exception as e:
|
| 484 |
+
# If template duplication fails, fall back to regular create
|
| 485 |
+
print(f"[Deploy] Template duplication failed, creating regular static space: {e}")
|
| 486 |
+
import traceback
|
| 487 |
+
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
api.create_repo(
|
| 489 |
repo_id=repo_id,
|
| 490 |
repo_type="space",
|
| 491 |
space_sdk=sdk,
|
| 492 |
private=private,
|
| 493 |
+
exist_ok=True # Don't fail if exists
|
| 494 |
)
|
| 495 |
+
else:
|
| 496 |
+
# For all other cases (new or update), ensure repo exists
|
| 497 |
+
print(f"[Deploy] Ensuring repo exists: {repo_id} (is_update={is_update})")
|
| 498 |
+
api.create_repo(
|
| 499 |
+
repo_id=repo_id,
|
| 500 |
+
repo_type="space",
|
| 501 |
+
space_sdk=sdk,
|
| 502 |
+
private=private if not is_update else None, # Only set private for new repos
|
| 503 |
+
exist_ok=True # Don't fail if repo already exists
|
| 504 |
+
)
|
| 505 |
+
except Exception as e:
|
| 506 |
+
return False, f"Failed to create/access space: {str(e)}", None
|
| 507 |
|
| 508 |
# Upload files
|
| 509 |
if not commit_message:
|
frontend/src/app/page.tsx
CHANGED
|
@@ -254,12 +254,12 @@ export default function Home() {
|
|
| 254 |
}
|
| 255 |
}
|
| 256 |
|
| 257 |
-
// Add deployment message to chat (
|
| 258 |
const deployMessage: Message = {
|
| 259 |
role: 'assistant',
|
| 260 |
content: existingSpace
|
| 261 |
-
? `β
Updated!
|
| 262 |
-
: `β
Deployed!
|
| 263 |
timestamp: new Date().toISOString(),
|
| 264 |
};
|
| 265 |
setMessages((prev) => [...prev, deployMessage]);
|
|
|
|
| 254 |
}
|
| 255 |
}
|
| 256 |
|
| 257 |
+
// Add deployment message to chat (EXACT Gradio format with markdown link)
|
| 258 |
const deployMessage: Message = {
|
| 259 |
role: 'assistant',
|
| 260 |
content: existingSpace
|
| 261 |
+
? `β
Updated! [Open your Space here](${response.space_url})`
|
| 262 |
+
: `β
Deployed! [Open your Space here](${response.space_url})`,
|
| 263 |
timestamp: new Date().toISOString(),
|
| 264 |
};
|
| 265 |
setMessages((prev) => [...prev, deployMessage]);
|