Spaces:
Paused
Paused
Download patch_restore_full_app.py from bep40/Space-Control: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/spaces/bep40/Space-Control/resolve/main/patch_restore_full_app.py
- Command line
-
hf download hf://spaces/bep40/Space-Control/patch_restore_full_app.py
-
curl -L -o patch_restore_full_app.py https://huggingface.co/spaces/bep40/Space-Control/resolve/main/patch_restore_full_app.py
2.74 kB
| """Restore the pre-retirement full app: App.tsx (frontend) + start.sh (backend). | |
| Upstream smolagents/ml-intern retired the hosted app: frontend App.tsx now | |
| renders RetirementPage ("ML Intern has moved to HuggingChat") and backend/start.sh | |
| now runs retired_main:app. That turns this Space into a static redirect page and | |
| the backend never starts, so our model patches have no visible effect. | |
| This patch overwrites both files with the last pre-retirement versions that this | |
| Space's Dockerfile was built on: | |
| - frontend/src/App.tsx -> full AppLayout + useAuth app | |
| - backend/start.sh -> uvicorn main:app (the real backend) | |
| Runs from either build stage: it patches whichever target exists and prints | |
| SKIP for the other (idempotent, re-runnable). | |
| """ | |
| import os | |
| FRONTEND_APP = r"""import { Box } from '@mui/material'; | |
| import AppLayout from '@/components/Layout/AppLayout'; | |
| import { useAuth } from '@/hooks/useAuth'; | |
| function App() { | |
| // Non-blocking auth check -- fires in background, updates store when done. | |
| // If auth fails later, apiFetch redirects to /auth/login. | |
| useAuth(); | |
| return ( | |
| <Box sx={{ height: '100vh', display: 'flex' }}> | |
| <AppLayout /> | |
| </Box> | |
| ); | |
| } | |
| export default App; | |
| """ | |
| BACKEND_START = r"""#!/bin/bash | |
| # Entrypoint for HF Spaces dev mode compatibility. | |
| # Dev mode spawns CMD multiple times simultaneously on restart. | |
| # Only the first instance can bind port 7860 - the rest must exit | |
| # with code 0 so the dev mode daemon doesn't mark the app as crashed. | |
| # Run uvicorn; if it fails due to port conflict, exit cleanly. | |
| uvicorn main:app --host 0.0.0.0 --port 7860 | |
| EXIT_CODE=$? | |
| if [ $EXIT_CODE -ne 0 ]; then | |
| # Check if this was a port-in-use failure (another instance already running) | |
| echo "uvicorn exited with code $EXIT_CODE, exiting gracefully." | |
| exit 0 | |
| fi | |
| """ | |
| def _write(path: str, content: str, executable: bool = False) -> bool: | |
| if not os.path.exists(path): | |
| return False | |
| with open(path, "w", encoding="utf-8") as f: | |
| f.write(content) | |
| if executable: | |
| os.chmod(path, 0o755) | |
| return True | |
| changed = False | |
| written = _write("/source/frontend/src/App.tsx", FRONTEND_APP) | |
| if written: | |
| print("OK: restored /source/frontend/src/App.tsx (full AppLayout app)") | |
| changed = True | |
| else: | |
| print("SKIP: /source/frontend/src/App.tsx not present (backend stage?)") | |
| written = _write("/app/backend/start.sh", BACKEND_START, executable=True) | |
| if written: | |
| print("OK: restored /app/backend/start.sh (uvicorn main:app)") | |
| changed = True | |
| else: | |
| print("SKIP: /app/backend/start.sh not present (frontend stage?)") | |
| if not changed: | |
| raise SystemExit("FAIL: neither target file found - unexpected layout") | |
| print("OK: full-app restore done") |