Spaces:
network01
/
Runtime error

akhaliq HF Staff commited on
Commit
1e9598c
·
1 Parent(s): fe27a3c

Fix transformers.js deployment: Upload all files (html, js, css) individually

Browse files

Issue: Transformers.js apps were not deploying correctly - CSS and JavaScript
files were missing from the deployed space.

Root cause: backend_deploy.py was using upload_folder() for all file types,
but transformers.js requires individual file uploads like the original deploy.py.

Changes to backend_deploy.py:

1. Added validation for transformers.js files:
- Check all three files exist (index.html, index.js, style.css)
- Return error if any file is missing

2. Template space duplication (NEW):
- Use duplicate_space() from static-templates/transformers.js template
- Matches original deploy.py behavior
- Falls back to create_repo() if duplication fails

3. Individual file upload for transformers.js:
- Added use_individual_uploads flag
- Upload each file separately using api.upload_file()
- NOT using upload_folder() for transformers.js

4. Retry logic with error handling:
- 3 attempts per file
- 2-second delay between retries
- Proper permission error detection
- User-friendly error messages

5. Separate commit messages:
- Each file gets its own commit: "{message} - {filename}"
- Preserves git history for each file

Upload flow for transformers.js:
1. Parse code to extract index.html, index.js, style.css
2. Validate all three files are present
3. Duplicate template space (or create static space)
4. Upload index.html individually (with retry)
5. Upload index.js individually (with retry)
6. Upload style.css individually (with retry)
7. Add anycoder tag to README

This matches the original deploy.py pattern where transformers.js files
are uploaded one at a time rather than as a folder.

Other languages (html, gradio, streamlit, react) continue to use
upload_folder() which works fine for them.

1 file changed +82 -14
backend_deploy.py+82-14