new update
Browse filesFiles changed (2)
- backend_deploy.py+12-7
- frontend/src/app/page.tsx+63-34
569 unmodified lines5705715725735745755765775785795805815825835845855865875885891 unmodified line591592593594595596597598599600601602569 unmodified linesfor attempt in range(max_attempts):try: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}")success = Trueprint(f"[Deploy] Successfully uploaded {filename}")breakexcept Exception as e:last_error = eif "403" in str(e) or "Forbidden" in str(e):return False, f"Permission denied uploading {filename}. Check your token has write access.", Noneif attempt < max_attempts - 1:time.sleep(2) # Wait before retryprint(f"[Deploy] Retry {attempt + 1}/{max_attempts} for {filename}")1 unmodified lineif not success:return False, f"Failed to upload {filename} after {max_attempts} attempts: {last_error}", Noneelse:# For other languages, use upload_folderapi.upload_folder(folder_path=str(temp_path),repo_id=repo_id,repo_type="space",commit_message=commit_message)except Exception as e:return False, f"Failed to upload files: {str(e)}", None569 unmodified lines5705715725735745755765775785795805815825835845855865875885895905915921 unmodified line594595596597598599600601602603604605606607569 unmodified linesfor attempt in range(max_attempts):try:# MATCH GRADIO: upload_file WITHOUT commit_message for individual filesapi.upload_file(path_or_fileobj=str(file_path),path_in_repo=filename,repo_id=repo_id,repo_type="space"# NO commit_message - HF API handles this automatically for spaces)success = Trueprint(f"[Deploy] Successfully uploaded {filename}")breakexcept Exception as e:last_error = eerror_str = str(e)print(f"[Deploy] Upload error for {filename}: {error_str}")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}.", Noneif attempt < max_attempts - 1:time.sleep(2) # Wait before retryprint(f"[Deploy] Retry {attempt + 1}/{max_attempts} for {filename}")1 unmodified lineif not success:return False, f"Failed to upload {filename} after {max_attempts} attempts: {last_error}", Noneelse:# For other languages, use upload_folder (Gradio uses individual files everywhere)# MATCH GRADIO: No commit_message for spacesprint(f"[Deploy] Uploading folder to {repo_id}")api.upload_folder(folder_path=str(temp_path),repo_id=repo_id,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)}", None
186 unmodified lines1871881891901911921 unmodified line1941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532541 unmodified line256257258259260261262263264186 unmodified linesreturn;}// SAME LOGIC AS GRADIO VERSION: Parse message history to find existing spacelet existingSpace: string | null = null;1 unmodified lineconsole.log('[Deploy] ========== DEBUG START ==========');console.log('[Deploy] Total messages in history:', messages.length);console.log('[Deploy] Current username:', username);console.log('[Deploy] Messages:', JSON.stringify(messages, null, 2));if (messages.length > 0 && username) {console.log('[Deploy] Scanning message history...');for (let i = messages.length - 1; i >= 0; 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')});// Check for deployment messagesif (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 update messagesif (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 imported space messages - THE KEY PART!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}/`));// Only use imported space if user owns it (can update it)if (importedSpace.startsWith(`${username}/`)) {existingSpace = importedSpace;console.log('[Deploy] β β β USER OWNS THIS SPACE! Will update:', existingSpace);break;} else {console.log('[Deploy] β οΈ User does not own this space:', importedSpace);console.log('[Deploy] Expected to start with:', `${username}/`);}} else {console.log('[Deploy] β Regex did not match URL in message');}}}1 unmodified lineconsole.log('[Deploy] Final existingSpace value:', existingSpace);} else {console.log('[Deploy] Skipping scan - no messages or no username');}console.log('[Deploy] ========== DEBUG END ==========');// Auto-generate space name (never prompt user)let spaceName = undefined; // undefined = backend will auto-generate186 unmodified lines1871881891901911921931941951961971981992002012022032042052062072082092102112122131 unmodified line2152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742751 unmodified line277278279280281282283284285286287288289290291292293186 unmodified linesreturn;}// CRITICAL: Wait for username to be loaded from authif (!username) {console.warn('[Deploy] Username not loaded yet, checking auth...');// Try to get username from auth statustry {const authStatus = await apiClient.getAuthStatus();if (authStatus.username) {setUsername(authStatus.username);// Retry deployment after setting usernamesetTimeout(() => 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 spacelet existingSpace: string | null = null;1 unmodified lineconsole.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 FORWARD (oldest first) - MATCHING GRADIO LOGIC...');console.log('[Deploy] Total messages to scan:', messages.length);// 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)});// Check assistant messages for deployment confirmationsif (msg.role === 'assistant') {// Check for "β Deployed!" messageif (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 "β Updated!" messageelse 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 user messages for importselse 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\)]+)/);if (match) {const importedSpace = match[1];console.log('[Deploy] Extracted imported space:', importedSpace);console.log('[Deploy] Checking ownership - user:', username, 'space:', importedSpace);// Only use if user owns it (EXACT GRADIO LOGIC)if (importedSpace.startsWith(`${username}/`)) {existingSpace = importedSpace;console.log('[Deploy] β β β USER OWNS - Will update:', existingSpace);break;} else {console.log('[Deploy] β οΈ User does NOT own - will create new space');// existing_space remains None (create new deployment)}}}}1 unmodified lineconsole.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 sentconsole.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