fix
Browse filesFiles changed (2)
1164 unmodified lines11651166116711681169117011711172117311741175117611771178117911809 unmodified lines1190119111921193119411951196119711981199120012011202120312041205120612071208118411851186118711881189119012091210121112121164 unmodified lines user_info = api.whoami() username = user_info.get("name") or user_info.get("preferred_username") or "user" # Get original space info to detect hardware print(f"[Duplicate] Fetching info for {from_space_id}") try: original_space_info = api.space_info(from_space_id) original_hardware = getattr(original_space_info, 'hardware', None) print(f"[Duplicate] Original space hardware: {original_hardware}") except Exception as e: print(f"[Duplicate] Could not fetch space info: {e}") original_hardware = None # If no destination name provided, use original name if not to_space_name: # Extract original space name9 unmodified lines print(f"[Duplicate] Duplicating {from_space_id} to {to_space_id}") # Prepare duplicate_space parameters duplicate_params = { "from_id": from_space_id, "to_id": to_space_name, # Just the name, not full ID "token": token, "private": private, "exist_ok": True } # Add hardware if the original space has it if original_hardware and original_hardware != 'cpu-basic': # Use the same hardware as original, or fallback to cpu-basic duplicate_params["hardware"] = original_hardware print(f"[Duplicate] Using hardware: {original_hardware}") # Duplicate the space duplicated_repo = duplicate_space( from_id=from_space_id, to_id=to_space_name, # Just the name, not full ID token=token, private=private, exist_ok=True ) duplicated_repo = duplicate_space(**duplicate_params) # Extract space URL space_url = f"https://huggingface.co/spaces/{to_space_id}"330 unmodified lines3313323333343353363373383343353363393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713373733743753763773783793803813823383393403413423434 unmodified lines348349350393394395396397398351352353354355356357358401402403404405359360361362363364365366367368369370371372330 unmodified lines return; } if (createPR) { // Option 1: Create a PR on the original space // Import code and let AI redesign it if (onImport && onStart) { onImport(result.code, result.language || 'html', redesignUrl); // Import code and trigger AI redesign (don't duplicate yet) if (onImport && onStart) { onImport(result.code, result.language || 'html', redesignUrl); // Send redesign prompt with code context setTimeout(async () => { const redesignPrompt = `I have existing code in the editor that I imported from ${redesignUrl}. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design.
Current code:\`\`\`${result.language || 'html'}${result.code}\`\`\`
Please redesign this with:- Minimal, clean components- Mobile-first responsive design- Modern UI/UX best practices- Better visual hierarchy and spacing`; if (onStart) { onStart(redesignPrompt, result.language || 'html', selectedModel); } console.log('[Redesign] Will create PR after code generation completes'); }, 100); setShowRedesignDialog(false); setRedesignUrl(''); } else { setRedesignError('Missing required callbacks. Please try again.'); } } else { // Option 2: Duplicate the space and then apply redesign console.log('[Redesign] Duplicating space for redesign:', repoId); const duplicateResult = await apiClient.duplicateSpace(repoId); if (duplicateResult.success) { // Show success message alert(`✅ Space duplicated successfully!\n\nYour space: ${duplicateResult.space_url}\n\nNow generating redesign...`); // Load the code and trigger redesign if (onImport && onStart) { onImport(result.code, result.language || 'html', duplicateResult.space_url); setTimeout(() => { const redesignPrompt = `I have existing code in the editor that I duplicated from ${redesignUrl}. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design. // Send redesign prompt with code context setTimeout(async () => { const redesignPrompt = `I have existing code in the editor that I imported from ${redesignUrl}. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design.
Current code:\`\`\`${result.language || 'html'}4 unmodified lines- Minimal, clean components- Mobile-first responsive design- Modern UI/UX best practices- Better visual hierarchy and spacing`; if (onStart) { onStart(redesignPrompt, result.language || 'html', selectedModel); } }, 100);- Better visual hierarchy and spacing
${createPR ? '\n\nNote: After generating the redesign, I will create a Pull Request on the original space.' : '\n\nNote: After generating the redesign, I can deploy to a new space or duplicate the original space.'}`; if (onStart) { onStart(redesignPrompt, result.language || 'html', selectedModel); } setShowRedesignDialog(false); setRedesignUrl(''); } else { setRedesignError(duplicateResult.message || 'Failed to duplicate space'); } if (createPR) { console.log('[Redesign] Will create PR after code generation completes'); } else { console.log('[Redesign] Code will be generated. User can deploy/duplicate after.'); } }, 100); setShowRedesignDialog(false); setRedesignUrl(''); } else { setRedesignError('Missing required callbacks. Please try again.'); } } catch (error: any) { console.error('Redesign error:', error);backend_deploy.py+26-7
frontend/src/components/LandingPage.tsx+23-59