update
Browse filesFiles changed (2)
460 unmodified lines461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496464465466467468469470471472473474475476477478479480481482483484485486487488489490491492502493494504505506507508509495496497498499500501502503504505506507508509460 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 space print(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 username print(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-name token=token, exist_ok=True ) print(f"[Deploy] Template duplication result: {result}") except Exception as e: # If template duplication fails, fall back to regular create print(f"[Deploy] Template duplication failed, creating regular static space: {e}") import traceback traceback.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 normally # 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 template print(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 username print(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-name token=token, exist_ok=True ) print(f"[Deploy] Template duplication result: {result}") except Exception as e: # If template duplication fails, fall back to regular create print(f"[Deploy] Template duplication failed, creating regular static space: {e}") import traceback traceback.print_exc() api.create_repo( repo_id=repo_id, repo_type="space", space_sdk=sdk, private=private, exist_ok=False exist_ok=True # Don't fail if exists ) except Exception as e: if "already exists" in str(e).lower(): # Space exists, treat as update is_update = True else: return False, f"Failed to create space: {str(e)}", None else: # For all other cases (new or update), ensure repo exists print(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 repos exist_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 files if not commit_message:253 unmodified lines254255256257257258259260261262261262263264265253 unmodified lines } } // Add deployment message to chat (matches Gradio format) // Add deployment message to chat (EXACT Gradio format with markdown link) const deployMessage: Message = { role: 'assistant', content: existingSpace ? `✅ Updated! View at: ${response.space_url}` : `✅ Deployed! View at: ${response.space_url}`, ? `✅ 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