update
Browse filesFiles changed (2)
460 unmodified lines461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512460 unmodified lines# Don't create README - HuggingFace will auto-generate it# We'll add the anycoder tag after deployment# Create the space (only for new deployments)if not is_update:try:if language == "transformers.js":# For transformers.js, duplicate the template spaceprint(f"[Deploy] Creating transformers.js space: {repo_id}")try:from huggingface_hub import duplicate_space# IMPORTANT: duplicate_space expects just the space name, not the full repo_id# It will automatically prepend the usernameprint(f"[Deploy] Attempting to duplicate template space to: {space_name}")result = duplicate_space(from_id="static-templates/transformers.js",to_id=space_name, # Just the space name, not username/space-nametoken=token,exist_ok=True)print(f"[Deploy] Template duplication result: {result}")except Exception as e:# If template duplication fails, fall back to regular createprint(f"[Deploy] Template duplication failed, creating regular static space: {e}")import tracebacktraceback.print_exc()api.create_repo(repo_id=repo_id,repo_type="space",space_sdk=sdk,private=private,exist_ok=False)else:# For other languages, create space normallyapi.create_repo(repo_id=repo_id,repo_type="space",space_sdk=sdk,private=private,exist_ok=False)except Exception as e:if "already exists" in str(e).lower():# Space exists, treat as updateis_update = Trueelse:return False, f"Failed to create space: {str(e)}", None# Upload filesif not commit_message:460 unmodified lines461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509460 unmodified lines# Don't create README - HuggingFace will auto-generate it# We'll add the anycoder tag after deployment# ALWAYS create/ensure repo exists (with exist_ok=True)# This works for both new spaces and updates!try:if language == "transformers.js" and not is_update:# For NEW transformers.js spaces, try to duplicate the templateprint(f"[Deploy] Creating new transformers.js space: {repo_id}")try:from huggingface_hub import duplicate_space# IMPORTANT: duplicate_space expects just the space name, not the full repo_id# It will automatically prepend the usernameprint(f"[Deploy] Attempting to duplicate template space to: {space_name}")result = duplicate_space(from_id="static-templates/transformers.js",to_id=space_name, # Just the space name, not username/space-nametoken=token,exist_ok=True)print(f"[Deploy] Template duplication result: {result}")except Exception as e:# If template duplication fails, fall back to regular createprint(f"[Deploy] Template duplication failed, creating regular static space: {e}")import tracebacktraceback.print_exc()api.create_repo(repo_id=repo_id,repo_type="space",space_sdk=sdk,private=private,exist_ok=True # Don't fail if exists)else:# For all other cases (new or update), ensure repo existsprint(f"[Deploy] Ensuring repo exists: {repo_id} (is_update={is_update})")api.create_repo(repo_id=repo_id,repo_type="space",space_sdk=sdk,private=private if not is_update else None, # Only set private for new reposexist_ok=True # Don't fail if repo already exists)except Exception as e:return False, f"Failed to create/access space: {str(e)}", None# Upload filesif not commit_message:
253 unmodified lines254255256257258259260261262263264265253 unmodified lines}}// Add deployment message to chat (matches Gradio format)const deployMessage: Message = {role: 'assistant',content: existingSpace? `✅ Updated! View at: ${response.space_url}`: `✅ Deployed! View at: ${response.space_url}`,timestamp: new Date().toISOString(),};setMessages((prev) => [...prev, deployMessage]);253 unmodified lines254255256257258259260261262263264265253 unmodified lines}}// Add deployment message to chat (EXACT Gradio format with markdown link)const deployMessage: Message = {role: 'assistant',content: existingSpace? `✅ Updated! [Open your Space here](${response.space_url})`: `✅ Deployed! [Open your Space here](${response.space_url})`,timestamp: new Date().toISOString(),};setMessages((prev) => [...prev, deployMessage]);
backend_deploy.py+37-40
frontend/src/app/page.tsx+3-3