akhaliq HF Staff commited on
Commit
d6a19c3
·
1 Parent(s): 2b0cf6a
backend_deploy.py CHANGED
@@ -1165,6 +1165,16 @@ def duplicate_space_to_user(
1165
  user_info = api.whoami()
1166
  username = user_info.get("name") or user_info.get("preferred_username") or "user"
1167
 
 
 
 
 
 
 
 
 
 
 
1168
  # If no destination name provided, use original name
1169
  if not to_space_name:
1170
  # Extract original space name
@@ -1180,14 +1190,23 @@ def duplicate_space_to_user(
1180
 
1181
  print(f"[Duplicate] Duplicating {from_space_id} to {to_space_id}")
1182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1183
  # Duplicate the space
1184
- duplicated_repo = duplicate_space(
1185
- from_id=from_space_id,
1186
- to_id=to_space_name, # Just the name, not full ID
1187
- token=token,
1188
- private=private,
1189
- exist_ok=True
1190
- )
1191
 
1192
  # Extract space URL
1193
  space_url = f"https://huggingface.co/spaces/{to_space_id}"
 
1165
  user_info = api.whoami()
1166
  username = user_info.get("name") or user_info.get("preferred_username") or "user"
1167
 
1168
+ # Get original space info to detect hardware
1169
+ print(f"[Duplicate] Fetching info for {from_space_id}")
1170
+ try:
1171
+ original_space_info = api.space_info(from_space_id)
1172
+ original_hardware = getattr(original_space_info, 'hardware', None)
1173
+ print(f"[Duplicate] Original space hardware: {original_hardware}")
1174
+ except Exception as e:
1175
+ print(f"[Duplicate] Could not fetch space info: {e}")
1176
+ original_hardware = None
1177
+
1178
  # If no destination name provided, use original name
1179
  if not to_space_name:
1180
  # Extract original space name
 
1190
 
1191
  print(f"[Duplicate] Duplicating {from_space_id} to {to_space_id}")
1192
 
1193
+ # Prepare duplicate_space parameters
1194
+ duplicate_params = {
1195
+ "from_id": from_space_id,
1196
+ "to_id": to_space_name, # Just the name, not full ID
1197
+ "token": token,
1198
+ "private": private,
1199
+ "exist_ok": True
1200
+ }
1201
+
1202
+ # Add hardware if the original space has it
1203
+ if original_hardware and original_hardware != 'cpu-basic':
1204
+ # Use the same hardware as original, or fallback to cpu-basic
1205
+ duplicate_params["hardware"] = original_hardware
1206
+ print(f"[Duplicate] Using hardware: {original_hardware}")
1207
+
1208
  # Duplicate the space
1209
+ duplicated_repo = duplicate_space(**duplicate_params)
 
 
 
 
 
 
1210
 
1211
  # Extract space URL
1212
  space_url = f"https://huggingface.co/spaces/{to_space_id}"
frontend/src/components/LandingPage.tsx CHANGED
@@ -331,55 +331,13 @@ export default function LandingPage({
331
  return;
332
  }
333
 
334
- if (createPR) {
335
- // Option 1: Create a PR on the original space
336
- // Import code and let AI redesign it
337
- if (onImport && onStart) {
338
- onImport(result.code, result.language || 'html', redesignUrl);
339
-
340
- // Send redesign prompt with code context
341
- setTimeout(async () => {
342
- 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.
343
-
344
- Current code:
345
- \`\`\`${result.language || 'html'}
346
- ${result.code}
347
- \`\`\`
348
-
349
- Please redesign this with:
350
- - Minimal, clean components
351
- - Mobile-first responsive design
352
- - Modern UI/UX best practices
353
- - Better visual hierarchy and spacing`;
354
-
355
- if (onStart) {
356
- onStart(redesignPrompt, result.language || 'html', selectedModel);
357
- }
358
-
359
- console.log('[Redesign] Will create PR after code generation completes');
360
- }, 100);
361
-
362
- setShowRedesignDialog(false);
363
- setRedesignUrl('');
364
- } else {
365
- setRedesignError('Missing required callbacks. Please try again.');
366
- }
367
- } else {
368
- // Option 2: Duplicate the space and then apply redesign
369
- console.log('[Redesign] Duplicating space for redesign:', repoId);
370
-
371
- const duplicateResult = await apiClient.duplicateSpace(repoId);
372
 
373
- if (duplicateResult.success) {
374
- // Show success message
375
- alert(`✅ Space duplicated successfully!\n\nYour space: ${duplicateResult.space_url}\n\nNow generating redesign...`);
376
-
377
- // Load the code and trigger redesign
378
- if (onImport && onStart) {
379
- onImport(result.code, result.language || 'html', duplicateResult.space_url);
380
-
381
- setTimeout(() => {
382
- 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.
383
 
384
  Current code:
385
  \`\`\`${result.language || 'html'}
@@ -390,19 +348,25 @@ Please redesign this with:
390
  - Minimal, clean components
391
  - Mobile-first responsive design
392
  - Modern UI/UX best practices
393
- - Better visual hierarchy and spacing`;
394
-
395
- if (onStart) {
396
- onStart(redesignPrompt, result.language || 'html', selectedModel);
397
- }
398
- }, 100);
399
  }
400
 
401
- setShowRedesignDialog(false);
402
- setRedesignUrl('');
403
- } else {
404
- setRedesignError(duplicateResult.message || 'Failed to duplicate space');
405
- }
 
 
 
 
 
 
406
  }
407
  } catch (error: any) {
408
  console.error('Redesign error:', error);
 
331
  return;
332
  }
333
 
334
+ // Import code and trigger AI redesign (don't duplicate yet)
335
+ if (onImport && onStart) {
336
+ onImport(result.code, result.language || 'html', redesignUrl);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
 
338
+ // Send redesign prompt with code context
339
+ setTimeout(async () => {
340
+ 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.
 
 
 
 
 
 
 
341
 
342
  Current code:
343
  \`\`\`${result.language || 'html'}
 
348
  - Minimal, clean components
349
  - Mobile-first responsive design
350
  - Modern UI/UX best practices
351
+ - Better visual hierarchy and spacing
352
+
353
+ ${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.'}`;
354
+
355
+ if (onStart) {
356
+ onStart(redesignPrompt, result.language || 'html', selectedModel);
357
  }
358
 
359
+ if (createPR) {
360
+ console.log('[Redesign] Will create PR after code generation completes');
361
+ } else {
362
+ console.log('[Redesign] Code will be generated. User can deploy/duplicate after.');
363
+ }
364
+ }, 100);
365
+
366
+ setShowRedesignDialog(false);
367
+ setRedesignUrl('');
368
+ } else {
369
+ setRedesignError('Missing required callbacks. Please try again.');
370
  }
371
  } catch (error: any) {
372
  console.error('Redesign error:', error);