Spaces:
Sleeping
Sleeping
fix
Browse files328 unmodified lines329330331332333334335336337338339340341342343139 unmodified lines48348448548648748848949049149249349449549649749849950050150210 unmodified lines513514515516517518519520521171 unmodified lines693694695696697698328 unmodified linesexcept Exception as e:return False, f"Failed to get user info: {str(e)}", None# Generate space name if not providedif not space_name:space_name = f"anycoder-{uuid.uuid4().hex[:8]}"# Clean space name (no spaces, lowercase, alphanumeric + hyphens)space_name = re.sub(r'[^a-z0-9-]', '-', space_name.lower())space_name = re.sub(r'-+', '-', space_name).strip('-')repo_id = f"{username}/{space_name}"# Detect SDKsdk = detect_sdk_from_code(code, language)139 unmodified linesif language == "transformers.js":if not is_update:print(f"[Deploy] Creating NEW transformers.js space via template duplication")try:from huggingface_hub import duplicate_space# duplicate_space expects just the space name (not full repo_id)# Use strip() to clean the space nameprint(f"[Deploy] Attempting to duplicate template space to: {space_name.strip()}")duplicated_repo = duplicate_space(from_id="static-templates/transformers.js",to_id=space_name.strip(),token=token,exist_ok=True)print(f"[Deploy] Template duplication result: {duplicated_repo} (type: {type(duplicated_repo)})")except Exception as e:# Handle potential RepoUrl object errorserror_msg = str(e)if "'url'" in error_msg or "RepoUrl" in error_msg:10 unmodified linesreturn False, f"Failed to create transformers.js space: {str(e)}", Noneelse:# Other errors - report themprint(f"[Deploy] Template duplication failed: {e}")import tracebacktraceback.print_exc()return False, f"Failed to create transformers.js space: {str(e)}", Noneelse:# For updates, verify we can access the existing space171 unmodified linesreturn True, f"✅ {action} successfully to {repo_id}!", space_urlexcept Exception as e:return False, f"Deployment error: {str(e)}", None328 unmodified lines329330331332333334335336337338339340341342343344345346347348349350139 unmodified lines49049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052110 unmodified lines532533534535536537171 unmodified lines709710711712713714715716717328 unmodified linesexcept Exception as e:return False, f"Failed to get user info: {str(e)}", None# Generate space name if not provided or emptyif not space_name or space_name.strip() == "":space_name = f"anycoder-{uuid.uuid4().hex[:8]}"print(f"[Deploy] Auto-generated space name: {space_name}")# Clean space name (no spaces, lowercase, alphanumeric + hyphens)space_name = re.sub(r'[^a-z0-9-]', '-', space_name.lower())space_name = re.sub(r'-+', '-', space_name).strip('-')# Ensure space_name is not empty after cleaningif not space_name:space_name = f"anycoder-{uuid.uuid4().hex[:8]}"print(f"[Deploy] Space name was empty after cleaning, regenerated: {space_name}")repo_id = f"{username}/{space_name}"print(f"[Deploy] Using repo_id: {repo_id}")# Detect SDKsdk = detect_sdk_from_code(code, language)139 unmodified linesif language == "transformers.js":if not is_update:print(f"[Deploy] Creating NEW transformers.js space via template duplication")print(f"[Deploy] space_name value: '{space_name}' (type: {type(space_name)})")# Safety check for space_nameif not space_name:return False, "Internal error: space_name is None after generation", Nonetry:from huggingface_hub import duplicate_space# duplicate_space expects just the space name (not full repo_id)# Use strip() to clean the space nameclean_space_name = space_name.strip()print(f"[Deploy] Attempting to duplicate template space to: {clean_space_name}")duplicated_repo = duplicate_space(from_id="static-templates/transformers.js",to_id=clean_space_name,token=token,exist_ok=True)print(f"[Deploy] Template duplication result: {duplicated_repo} (type: {type(duplicated_repo)})")except Exception as e:print(f"[Deploy] Exception during duplicate_space: {type(e).__name__}: {str(e)}")import tracebacktraceback.print_exc()# Handle potential RepoUrl object errorserror_msg = str(e)if "'url'" in error_msg or "RepoUrl" in error_msg:10 unmodified linesreturn False, f"Failed to create transformers.js space: {str(e)}", Noneelse:# Other errors - report themreturn False, f"Failed to create transformers.js space: {str(e)}", Noneelse:# For updates, verify we can access the existing space171 unmodified linesreturn True, f"✅ {action} successfully to {repo_id}!", space_urlexcept Exception as e:print(f"[Deploy] Top-level exception caught: {type(e).__name__}: {str(e)}")import tracebacktraceback.print_exc()return False, f"Deployment error: {str(e)}", None
backend_deploy.py+26-7