Spaces:
Running
Running
update svelte
Browse files
app.py
CHANGED
|
@@ -7707,6 +7707,7 @@ with gr.Blocks(
|
|
| 7707 |
# For new spaces, duplicate the template first
|
| 7708 |
if not is_update:
|
| 7709 |
from huggingface_hub import duplicate_space
|
|
|
|
| 7710 |
duplicated_repo = duplicate_space(
|
| 7711 |
from_id="static-templates/svelte",
|
| 7712 |
to_id=repo_id,
|
|
@@ -7724,6 +7725,11 @@ with gr.Blocks(
|
|
| 7724 |
except Exception as e:
|
| 7725 |
print(f"Error extracting repo ID from duplicated_repo: {e}")
|
| 7726 |
actual_repo_id = repo_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7727 |
print("Actual repo ID for Svelte uploads:", actual_repo_id)
|
| 7728 |
|
| 7729 |
# Parse all generated Svelte files (dynamic multi-file)
|
|
@@ -7748,7 +7754,7 @@ with gr.Blocks(
|
|
| 7748 |
print(f"[Svelte Deploy] package.json synthesis skipped: {e}")
|
| 7749 |
|
| 7750 |
# Write all files to a temp directory and upload folder in one commit
|
| 7751 |
-
import tempfile, os
|
| 7752 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 7753 |
for rel_path, content in files.items():
|
| 7754 |
safe_rel = (rel_path or '').strip().lstrip('/')
|
|
@@ -7756,14 +7762,40 @@ with gr.Blocks(
|
|
| 7756 |
os.makedirs(os.path.dirname(abs_path), exist_ok=True)
|
| 7757 |
with open(abs_path, 'w') as fh:
|
| 7758 |
fh.write(content or '')
|
| 7759 |
-
|
| 7760 |
-
|
| 7761 |
-
|
| 7762 |
-
|
| 7763 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7764 |
|
| 7765 |
-
# Add anycoder tag to existing README
|
| 7766 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7767 |
|
| 7768 |
# Success
|
| 7769 |
space_url = f"https://huggingface.co/spaces/{actual_repo_id}"
|
|
|
|
| 7707 |
# For new spaces, duplicate the template first
|
| 7708 |
if not is_update:
|
| 7709 |
from huggingface_hub import duplicate_space
|
| 7710 |
+
import time
|
| 7711 |
duplicated_repo = duplicate_space(
|
| 7712 |
from_id="static-templates/svelte",
|
| 7713 |
to_id=repo_id,
|
|
|
|
| 7725 |
except Exception as e:
|
| 7726 |
print(f"Error extracting repo ID from duplicated_repo: {e}")
|
| 7727 |
actual_repo_id = repo_id
|
| 7728 |
+
|
| 7729 |
+
# Small delay to allow the duplication to fully complete and reduce race conditions
|
| 7730 |
+
print("Waiting for template duplication to complete...")
|
| 7731 |
+
time.sleep(3)
|
| 7732 |
+
|
| 7733 |
print("Actual repo ID for Svelte uploads:", actual_repo_id)
|
| 7734 |
|
| 7735 |
# Parse all generated Svelte files (dynamic multi-file)
|
|
|
|
| 7754 |
print(f"[Svelte Deploy] package.json synthesis skipped: {e}")
|
| 7755 |
|
| 7756 |
# Write all files to a temp directory and upload folder in one commit
|
| 7757 |
+
import tempfile, os, time
|
| 7758 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 7759 |
for rel_path, content in files.items():
|
| 7760 |
safe_rel = (rel_path or '').strip().lstrip('/')
|
|
|
|
| 7762 |
os.makedirs(os.path.dirname(abs_path), exist_ok=True)
|
| 7763 |
with open(abs_path, 'w') as fh:
|
| 7764 |
fh.write(content or '')
|
| 7765 |
+
|
| 7766 |
+
# Retry logic for upload_folder to handle race conditions
|
| 7767 |
+
max_retries = 3
|
| 7768 |
+
for attempt in range(max_retries):
|
| 7769 |
+
try:
|
| 7770 |
+
api.upload_folder(
|
| 7771 |
+
folder_path=tmpdir,
|
| 7772 |
+
repo_id=actual_repo_id,
|
| 7773 |
+
repo_type="space"
|
| 7774 |
+
)
|
| 7775 |
+
break # Success, exit retry loop
|
| 7776 |
+
except Exception as upload_error:
|
| 7777 |
+
if "commit has happened since" in str(upload_error).lower() and attempt < max_retries - 1:
|
| 7778 |
+
print(f"Svelte upload attempt {attempt + 1} failed due to race condition, retrying in 2 seconds...")
|
| 7779 |
+
time.sleep(2) # Wait before retry
|
| 7780 |
+
continue
|
| 7781 |
+
else:
|
| 7782 |
+
raise upload_error # Re-raise if not a race condition or max retries reached
|
| 7783 |
|
| 7784 |
+
# Add anycoder tag to existing README (with retry logic)
|
| 7785 |
+
max_retries = 3
|
| 7786 |
+
for attempt in range(max_retries):
|
| 7787 |
+
try:
|
| 7788 |
+
add_anycoder_tag_to_readme(api, actual_repo_id)
|
| 7789 |
+
break # Success, exit retry loop
|
| 7790 |
+
except Exception as readme_error:
|
| 7791 |
+
if "commit has happened since" in str(readme_error).lower() and attempt < max_retries - 1:
|
| 7792 |
+
print(f"README tag attempt {attempt + 1} failed due to race condition, retrying in 2 seconds...")
|
| 7793 |
+
time.sleep(2) # Wait before retry
|
| 7794 |
+
continue
|
| 7795 |
+
else:
|
| 7796 |
+
# Non-fatal: README tagging is not critical, just log and continue
|
| 7797 |
+
print(f"Failed to add anycoder tag to README after {max_retries} attempts: {readme_error}")
|
| 7798 |
+
break
|
| 7799 |
|
| 7800 |
# Success
|
| 7801 |
space_url = f"https://huggingface.co/spaces/{actual_repo_id}"
|