akhaliq HF Staff commited on
Commit
8377411
·
1 Parent(s): 03ad9bd

fix deploy issue

Browse files
backend_deploy.py CHANGED
@@ -538,8 +538,54 @@ def deploy_to_huggingface_space(
538
  print(f"[Deploy] history provided: {history is not None} (length: {len(history) if history else 0})")
539
  print(f"[Deploy] username: {username}")
540
  print(f"[Deploy] is_update: {is_update}")
 
541
  print(f"[Deploy] ============================================")
542
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  if is_update:
544
  # Use existing repo
545
  repo_id = existing_repo_id
 
538
  print(f"[Deploy] history provided: {history is not None} (length: {len(history) if history else 0})")
539
  print(f"[Deploy] username: {username}")
540
  print(f"[Deploy] is_update: {is_update}")
541
+ print(f"[Deploy] language: {language}")
542
  print(f"[Deploy] ============================================")
543
 
544
+ # For Gradio space updates (import/redesign), only update .py files
545
+ if is_update and language == "gradio":
546
+ print(f"[Deploy] Gradio space update - will only update .py files")
547
+
548
+ # Parse the code to get all files
549
+ files = parse_multi_file_python_output(code)
550
+
551
+ # Fallback if no files parsed
552
+ if not files:
553
+ print(f"[Deploy] No file markers found, using entire code as app.py")
554
+ cleaned_code = remove_code_block(code)
555
+ files['app.py'] = cleaned_code
556
+
557
+ # Filter to only .py files
558
+ py_files = {fname: content for fname, content in files.items() if fname.endswith('.py')}
559
+
560
+ if not py_files:
561
+ return False, "Error: No Python files found in generated code", None
562
+
563
+ print(f"[Deploy] Updating {len(py_files)} Python file(s): {list(py_files.keys())}")
564
+
565
+ # Update each Python file individually
566
+ updated_files = []
567
+ for file_path, content in py_files.items():
568
+ print(f"[Deploy] Updating {file_path} ({len(content)} chars)")
569
+ success, msg = update_space_file(
570
+ repo_id=existing_repo_id,
571
+ file_path=file_path,
572
+ content=content,
573
+ token=token,
574
+ commit_message=commit_message or f"Update {file_path} from anycoder"
575
+ )
576
+
577
+ if success:
578
+ updated_files.append(file_path)
579
+ else:
580
+ print(f"[Deploy] Warning: Failed to update {file_path}: {msg}")
581
+
582
+ if updated_files:
583
+ space_url = f"https://huggingface.co/spaces/{existing_repo_id}"
584
+ files_list = ", ".join(updated_files)
585
+ return True, f"✅ Updated {len(updated_files)} file(s): {files_list}! View at: {space_url}", space_url
586
+ else:
587
+ return False, "Failed to update any Python files", None
588
+
589
  if is_update:
590
  # Use existing repo
591
  repo_id = existing_repo_id
frontend/src/components/LandingPage.tsx CHANGED
@@ -371,6 +371,7 @@ export default function LandingPage({
371
  console.log('[Redesign] Duplicated space ID:', duplicatedRepoId);
372
 
373
  setTimeout(() => {
 
374
  const redesignPrompt = `I have existing code in the editor from a duplicated space. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design.
375
 
376
  Current code:
@@ -382,7 +383,9 @@ Please redesign this with:
382
  - Minimal, clean components
383
  - Mobile-first responsive design
384
  - Modern UI/UX best practices
385
- - Better visual hierarchy and spacing`;
 
 
386
 
387
  if (onStart) {
388
  // Pass duplicated space ID so auto-deploy updates it
@@ -411,6 +414,7 @@ Please redesign this with:
411
  onImport(result.code, result.language || 'html', redesignUrl);
412
 
413
  setTimeout(() => {
 
414
  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.
415
 
416
  Current code:
@@ -424,6 +428,8 @@ Please redesign this with:
424
  - Modern UI/UX best practices
425
  - Better visual hierarchy and spacing
426
 
 
 
427
  Note: After generating the redesign, I will create a Pull Request on the original space.`;
428
 
429
  if (onStart) {
 
371
  console.log('[Redesign] Duplicated space ID:', duplicatedRepoId);
372
 
373
  setTimeout(() => {
374
+ const isGradio = (result.language || 'html') === 'gradio';
375
  const redesignPrompt = `I have existing code in the editor from a duplicated space. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design.
376
 
377
  Current code:
 
383
  - Minimal, clean components
384
  - Mobile-first responsive design
385
  - Modern UI/UX best practices
386
+ - Better visual hierarchy and spacing
387
+
388
+ ${isGradio ? '\n\nIMPORTANT: Only output Python (.py) files. Do NOT include requirements.txt or any other non-Python files. The existing dependencies and configuration files will be preserved.' : ''}`;
389
 
390
  if (onStart) {
391
  // Pass duplicated space ID so auto-deploy updates it
 
414
  onImport(result.code, result.language || 'html', redesignUrl);
415
 
416
  setTimeout(() => {
417
+ const isGradio = (result.language || 'html') === 'gradio';
418
  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.
419
 
420
  Current code:
 
428
  - Modern UI/UX best practices
429
  - Better visual hierarchy and spacing
430
 
431
+ ${isGradio ? '\n\nIMPORTANT: Only output Python (.py) files. Do NOT include requirements.txt or any other non-Python files. The existing dependencies and configuration files will be preserved.' : ''}
432
+
433
  Note: After generating the redesign, I will create a Pull Request on the original space.`;
434
 
435
  if (onStart) {