Spaces:
Running
Running
multi file deploy
Browse files
app.py
CHANGED
@@ -6368,12 +6368,50 @@ with gr.Blocks(
|
|
6368 |
# Other SDKs (existing logic)
|
6369 |
if sdk == "static":
|
6370 |
import time
|
6371 |
-
file_name = "index.html"
|
6372 |
|
6373 |
# Add anycoder tag to existing README (after repo creation)
|
6374 |
add_anycoder_tag_to_readme(api, repo_id)
|
6375 |
|
6376 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6377 |
max_attempts = 3
|
6378 |
for attempt in range(max_attempts):
|
6379 |
import tempfile
|
@@ -6395,7 +6433,7 @@ with gr.Blocks(
|
|
6395 |
if "403 Forbidden" in error_msg and "write token" in error_msg:
|
6396 |
return gr.update(value=f"Error: Permission denied. Please ensure you have write access to {repo_id} and your token has the correct permissions.", visible=True)
|
6397 |
elif attempt < max_attempts - 1:
|
6398 |
-
time.sleep(2)
|
6399 |
else:
|
6400 |
return gr.update(value=f"Error uploading file after {max_attempts} attempts: {e}. Please check your permissions and try again.", visible=True)
|
6401 |
finally:
|
|
|
6368 |
# Other SDKs (existing logic)
|
6369 |
if sdk == "static":
|
6370 |
import time
|
|
|
6371 |
|
6372 |
# Add anycoder tag to existing README (after repo creation)
|
6373 |
add_anycoder_tag_to_readme(api, repo_id)
|
6374 |
|
6375 |
+
# Detect whether the HTML output is multi-file (=== filename === blocks)
|
6376 |
+
files = {}
|
6377 |
+
try:
|
6378 |
+
files = parse_multipage_html_output(code)
|
6379 |
+
except Exception:
|
6380 |
+
files = {}
|
6381 |
+
|
6382 |
+
# If we have multiple files (or at least a parsed index.html), upload the whole folder
|
6383 |
+
if isinstance(files, dict) and files.get('index.html'):
|
6384 |
+
import tempfile
|
6385 |
+
import os
|
6386 |
+
|
6387 |
+
try:
|
6388 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
6389 |
+
# Write each file preserving subdirectories if any
|
6390 |
+
for rel_path, content in files.items():
|
6391 |
+
safe_rel_path = rel_path.strip().lstrip('/')
|
6392 |
+
abs_path = os.path.join(tmpdir, safe_rel_path)
|
6393 |
+
os.makedirs(os.path.dirname(abs_path), exist_ok=True)
|
6394 |
+
with open(abs_path, 'w') as fh:
|
6395 |
+
fh.write(content)
|
6396 |
+
|
6397 |
+
# Upload the folder in a single commit
|
6398 |
+
api.upload_folder(
|
6399 |
+
folder_path=tmpdir,
|
6400 |
+
repo_id=repo_id,
|
6401 |
+
repo_type="space"
|
6402 |
+
)
|
6403 |
+
space_url = f"https://huggingface.co/spaces/{repo_id}"
|
6404 |
+
action_text = "Updated" if is_update else "Deployed"
|
6405 |
+
return gr.update(value=f"✅ {action_text}! [Open your Space here]({space_url})", visible=True)
|
6406 |
+
except Exception as e:
|
6407 |
+
error_msg = str(e)
|
6408 |
+
if "403 Forbidden" in error_msg and "write token" in error_msg:
|
6409 |
+
return gr.update(value=f"Error: Permission denied. Please ensure you have write access to {repo_id} and your token has the correct permissions.", visible=True)
|
6410 |
+
else:
|
6411 |
+
return gr.update(value=f"Error uploading static app folder: {e}", visible=True)
|
6412 |
+
|
6413 |
+
# Fallback: single-file static HTML (upload index.html only)
|
6414 |
+
file_name = "index.html"
|
6415 |
max_attempts = 3
|
6416 |
for attempt in range(max_attempts):
|
6417 |
import tempfile
|
|
|
6433 |
if "403 Forbidden" in error_msg and "write token" in error_msg:
|
6434 |
return gr.update(value=f"Error: Permission denied. Please ensure you have write access to {repo_id} and your token has the correct permissions.", visible=True)
|
6435 |
elif attempt < max_attempts - 1:
|
6436 |
+
time.sleep(2)
|
6437 |
else:
|
6438 |
return gr.update(value=f"Error uploading file after {max_attempts} attempts: {e}. Please check your permissions and try again.", visible=True)
|
6439 |
finally:
|