multi file deploy
Browse files6367 unmodified lines63686369637063716372637363746375637663776378637915 unmodified lines63956396639763986399640064016367 unmodified lines# Other SDKs (existing logic)if sdk == "static":import timefile_name = "index.html"# Add anycoder tag to existing README (after repo creation)add_anycoder_tag_to_readme(api, repo_id)# Wait and retry logic after repo creationmax_attempts = 3for attempt in range(max_attempts):import tempfile15 unmodified linesif "403 Forbidden" in error_msg and "write token" in error_msg: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)elif attempt < max_attempts - 1:time.sleep(2) # Wait before retryingelse:return gr.update(value=f"Error uploading file after {max_attempts} attempts: {e}. Please check your permissions and try again.", visible=True)finally:6367 unmodified lines6368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641715 unmodified lines64336434643564366437643864396367 unmodified lines# Other SDKs (existing logic)if sdk == "static":import time# Add anycoder tag to existing README (after repo creation)add_anycoder_tag_to_readme(api, repo_id)# Detect whether the HTML output is multi-file (=== filename === blocks)files = {}try:files = parse_multipage_html_output(code)except Exception:files = {}# If we have multiple files (or at least a parsed index.html), upload the whole folderif isinstance(files, dict) and files.get('index.html'):import tempfileimport ostry:with tempfile.TemporaryDirectory() as tmpdir:# Write each file preserving subdirectories if anyfor rel_path, content in files.items():safe_rel_path = rel_path.strip().lstrip('/')abs_path = os.path.join(tmpdir, safe_rel_path)os.makedirs(os.path.dirname(abs_path), exist_ok=True)with open(abs_path, 'w') as fh:fh.write(content)# Upload the folder in a single commitapi.upload_folder(folder_path=tmpdir,repo_id=repo_id,repo_type="space")space_url = f"https://huggingface.co/spaces/{repo_id}"action_text = "Updated" if is_update else "Deployed"return gr.update(value=f"✅ {action_text}! [Open your Space here]({space_url})", visible=True)except Exception as e:error_msg = str(e)if "403 Forbidden" in error_msg and "write token" in error_msg: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)else:return gr.update(value=f"Error uploading static app folder: {e}", visible=True)# Fallback: single-file static HTML (upload index.html only)file_name = "index.html"max_attempts = 3for attempt in range(max_attempts):import tempfile15 unmodified linesif "403 Forbidden" in error_msg and "write token" in error_msg: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)elif attempt < max_attempts - 1:time.sleep(2)else:return gr.update(value=f"Error uploading file after {max_attempts} attempts: {e}. Please check your permissions and try again.", visible=True)finally:
app.py+41-3