Spaces:
network01
/
Runtime error

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

Add follow-up deployment support: Update existing spaces instead of creating new ones

Browse files

Implemented the same pattern as original deploy.py where follow-up prompts
update the existing deployed space with new commits instead of creating new spaces.

backend_deploy.py changes:
- Added existing_repo_id parameter to deploy_to_huggingface_space()
- Added commit_message parameter for custom commit messages
- Added is_update logic to detect updates vs new deployments
- Skip create_repo() when updating existing space
- Use appropriate commit message: "Update from anycoder" vs "Deploy from anycoder"
- Return different success message: "Updated" vs "Deployed"
- Skip 2-second wait for README on updates (already exists)

backend_api.py changes:
- Updated DeploymentRequest model to include:
* existing_repo_id (optional) - for explicitly updating a space
* commit_message (optional) - custom commit message
* space_name now optional (not needed for updates)
- Added deployed_spaces tracking to user_sessions
- Deploy endpoint now:
* Checks session for previously deployed spaces
* Automatically finds most recent space for same language
* Passes existing_repo_id to deployment function
* Tracks deployed spaces after successful deployment
* Returns repo_id in response for frontend tracking

Deployment flow:
1. First deployment: Creates new space, tracks in session
2. Follow-up for same language: Finds existing space from session
3. Updates that space with new commit (preserves git history)
4. Each update creates a new commit in the space's git repo

This matches the original Gradio UI behavior where:
- Initial "make a gradio app" creates new space
- Follow-up "add a button" updates the same space
- History is preserved with proper git commits

Session tracking ensures follow-up prompts in the same session
automatically update the correct space without user intervention.

2 files changed +106 -43
Files changed (2)
backend_api.py+47-3
backend_deploy.py+59-40