new update
Browse filesFiles changed (2)
- backend_deploy.py+12-7
- frontend/src/app/page.tsx+63-34
569 unmodified lines5705715725735745755765775775785785795805815825835845855865875855865885895905915921 unmodified line594595596594597598599600601602598599603604605606607569 unmodified lines for attempt in range(max_attempts): try: # MATCH GRADIO: upload_file WITHOUT commit_message for individual files api.upload_file( path_or_fileobj=str(file_path), path_in_repo=filename, repo_id=repo_id, repo_type="space", commit_message=f"{commit_message} - {filename}" repo_type="space" # NO commit_message - HF API handles this automatically for spaces ) success = True print(f"[Deploy] Successfully uploaded {filename}") break except Exception as e: last_error = e error_str = str(e) print(f"[Deploy] Upload error for {filename}: {error_str}") if "403" in str(e) or "Forbidden" in str(e): return False, f"Permission denied uploading {filename}. Check your token has write access.", None if "403" in error_str or "Forbidden" in error_str: return False, f"Permission denied uploading {filename}. Check your token has write access to {repo_id}.", None if attempt < max_attempts - 1: time.sleep(2) # Wait before retry print(f"[Deploy] Retry {attempt + 1}/{max_attempts} for {filename}")1 unmodified line if not success: return False, f"Failed to upload {filename} after {max_attempts} attempts: {last_error}", None else: # For other languages, use upload_folder # For other languages, use upload_folder (Gradio uses individual files everywhere) # MATCH GRADIO: No commit_message for spaces print(f"[Deploy] Uploading folder to {repo_id}") api.upload_folder( folder_path=str(temp_path), repo_id=repo_id, repo_type="space", commit_message=commit_message repo_type="space" # NO commit_message - HF API handles this automatically for spaces ) except Exception as e: return False, f"Failed to upload files: {str(e)}", None186 unmodified lines1871881891901911921931941951961971981992002012022032042052062072082092102112122131 unmodified line2152162172182192202212002222232242022252262272282292302062072312322332342352102112122132142152162362372382392402412422432442182192202212222232242252262452462472482492502512522532542292302312322552562572582342592602372382392612622632412642652662442672682692472482702712722502512732742751 unmodified line277278279280281282283284285286287288289290291292293186 unmodified lines return; }
// CRITICAL: Wait for username to be loaded from auth if (!username) { console.warn('[Deploy] Username not loaded yet, checking auth...'); // Try to get username from auth status try { const authStatus = await apiClient.getAuthStatus(); if (authStatus.username) { setUsername(authStatus.username); // Retry deployment after setting username setTimeout(() => handleDeploy(), 100); return; } else { alert('Please log in to deploy your app'); return; } } catch (e) { alert('Please log in to deploy your app'); return; } }
// SAME LOGIC AS GRADIO VERSION: Parse message history to find existing space let existingSpace: string | null = null; 1 unmodified line console.log('[Deploy] ========== DEBUG START =========='); console.log('[Deploy] Total messages in history:', messages.length); console.log('[Deploy] Current username:', username); console.log('[Deploy] Auth status:', isAuthenticated ? 'authenticated' : 'not authenticated'); console.log('[Deploy] Messages:', JSON.stringify(messages, null, 2)); if (messages.length > 0 && username) { console.log('[Deploy] Scanning message history...'); console.log('[Deploy] Scanning message history FORWARD (oldest first) - MATCHING GRADIO LOGIC...'); console.log('[Deploy] Total messages to scan:', messages.length); for (let i = messages.length - 1; i >= 0; i--) { // EXACT GRADIO LOGIC: Scan forward (oldest first) and stop at first match // Gradio: for user_msg, assistant_msg in history: for (let i = 0; i < messages.length; i++) { const msg = messages[i]; console.log(`[Deploy] Checking message ${i}:`, { role: msg.role, contentPreview: msg.content.substring(0, 100), startsWithImported: msg.content.startsWith('Imported Space from') contentPreview: msg.content.substring(0, 100) }); // Check assistant messages for deployment confirmations if (msg.role === 'assistant') { // Check for deployment messages if (msg.role === 'assistant' && msg.content.includes('β
Deployed')) { const match = msg.content.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/); if (match) { existingSpace = match[1]; console.log('[Deploy] β
Found "β
Deployed" message:', existingSpace); break; // Check for "β
Deployed!" message if (msg.content.includes('β
Deployed!')) { const match = msg.content.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/); if (match) { existingSpace = match[1]; console.log('[Deploy] β
Found "β
Deployed!" - existing_space:', existingSpace); break; } } } // Check for update messages if (msg.role === 'assistant' && msg.content.includes('β
Updated')) { const match = msg.content.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/); if (match) { existingSpace = match[1]; console.log('[Deploy] β
Found "β
Updated" message:', existingSpace); break; // Check for "β
Updated!" message else if (msg.content.includes('β
Updated!')) { const match = msg.content.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/); if (match) { existingSpace = match[1]; console.log('[Deploy] β
Found "β
Updated!" - existing_space:', existingSpace); break; } } } // Check for imported space messages - THE KEY PART! if (msg.role === 'user' && msg.content.startsWith('Imported Space from')) { console.log('[Deploy] π― Found "Imported Space from" message!'); // Check user messages for imports else if (msg.role === 'user' && msg.content.startsWith('Imported Space from')) { console.log('[Deploy] π― Found "Imported Space from" message'); const match = msg.content.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/); console.log('[Deploy] Regex match result:', match); if (match) { const importedSpace = match[1]; console.log('[Deploy] Extracted space:', importedSpace); console.log('[Deploy] Username to check:', username); console.log('[Deploy] Starts with username?', importedSpace.startsWith(`${username}/`)); console.log('[Deploy] Extracted imported space:', importedSpace); console.log('[Deploy] Checking ownership - user:', username, 'space:', importedSpace); // Only use imported space if user owns it (can update it) // Only use if user owns it (EXACT GRADIO LOGIC) if (importedSpace.startsWith(`${username}/`)) { existingSpace = importedSpace; console.log('[Deploy] β
β
β
USER OWNS THIS SPACE! Will update:', existingSpace); console.log('[Deploy] β
β
β
USER OWNS - Will update:', existingSpace); break; } else { console.log('[Deploy] β οΈ User does not own this space:', importedSpace); console.log('[Deploy] Expected to start with:', `${username}/`); console.log('[Deploy] β οΈ User does NOT own - will create new space'); // existing_space remains None (create new deployment) } } else { console.log('[Deploy] β Regex did not match URL in message'); } } }1 unmodified line console.log('[Deploy] Final existingSpace value:', existingSpace); } else { console.log('[Deploy] Skipping scan - no messages or no username'); console.log('[Deploy] Messages length:', messages.length); console.log('[Deploy] Username:', username); } console.log('[Deploy] ========== DEBUG END ==========');
// TEMPORARY DEBUG: Show what will be sent console.log('[Deploy] π ABOUT TO DEPLOY:'); console.log('[Deploy] - Language:', selectedLanguage); console.log('[Deploy] - existing_repo_id:', existingSpace || 'None (new deployment)'); console.log('[Deploy] - Username:', username);
// Auto-generate space name (never prompt user) let spaceName = undefined; // undefined = backend will auto-generate
backend_deploy.py+12-7
frontend/src/app/page.tsx+63-34