update
Browse files915 unmodified lines916917918919919920921922923924925926927928929923924925926927216 unmodified lines114411451146115211531154115511561157115811591160114711481149115011511152116711531154116911701171117211551156115711581159116011761177117811791180116111621163915 unmodified lines print(f"[Deploy] {error_msg}") return False, error_msg, None # Write transformers.js files to temp directory # Write transformers.js files to temp directory for filename, content in files.items(): file_path = temp_path / filename print(f"[Deploy] Writing {filename} ({len(content)} chars) to {file_path}") # Use binary mode with UTF-8 encoding for better emoji/special character handling try: file_path.write_bytes(content.encode('utf-8')) except UnicodeEncodeError as e: print(f"[Deploy] Encoding error in {filename}: {e}, using fallback encoding") # Fallback: ignore problematic characters file_path.write_bytes(content.encode('utf-8', errors='ignore')) # Use text mode - Python handles encoding automatically file_path.write_text(content, encoding='utf-8') # Verify the write was successful written_size = file_path.stat().st_size print(f"[Deploy] Verified {filename}: {written_size} bytes on disk")216 unmodified lines if not file_content: return False, f"Missing content for {file_name}", None # Ensure content is properly encoded (handle emojis safely) try: # Test encoding - this will catch any encoding issues early file_content.encode('utf-8', errors='strict') except UnicodeEncodeError as e: print(f"[Deploy] Encoding warning for {file_name}: {e}") # Replace problematic characters with safe equivalents file_content = file_content.encode('utf-8', errors='ignore').decode('utf-8') success = False last_error = None for attempt in range(max_attempts): temp_file_path = None try: # Create a NEW temp file for this upload (key difference from old approach) # Create a NEW temp file for this upload (matches Gradio version approach) print(f"[Deploy] Creating temp file for {file_name} with {len(file_content)} chars") # Use binary mode with explicit UTF-8 encoding for better emoji handling with tempfile.NamedTemporaryFile("wb", suffix=f".{file_name.split('.')[-1]}", delete=False) as f: f.write(file_content.encode('utf-8')) f.flush() # Ensure all content is written to disk before closing # Use text mode "w" - lets Python handle encoding automatically (better emoji support) with tempfile.NamedTemporaryFile("w", suffix=f".{file_name.split('.')[-1]}", delete=False) as f: f.write(file_content) temp_file_path = f.name # File is now closed and flushed, safe to upload # Verify temp file size before upload import os as _os temp_size = _os.path.getsize(temp_file_path) print(f"[Deploy] Temp file {file_name} size on disk: {temp_size} bytes (expected ~{len(file_content)} chars)") # Upload the file without commit_message (HF handles this for spaces) api.upload_file( path_or_fileobj=temp_file_path,backend_deploy.py+7-27