bep40 commited on
Commit
1d6872e
·
verified ·
1 Parent(s): 8ddc36d

Upload patch_restore_full_app.py

Browse files
Files changed (1) hide show
  1. patch_restore_full_app.py +84 -0
patch_restore_full_app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Restore the pre-retirement full app: App.tsx (frontend) + start.sh (backend).
2
+
3
+ Upstream smolagents/ml-intern retired the hosted app: frontend App.tsx now
4
+ renders RetirementPage ("ML Intern has moved to HuggingChat") and backend/start.sh
5
+ now runs retired_main:app. That turns this Space into a static redirect page and
6
+ the backend never starts, so our model patches have no visible effect.
7
+
8
+ This patch overwrites both files with the last pre-retirement versions that this
9
+ Space's Dockerfile was built on:
10
+ - frontend/src/App.tsx -> full AppLayout + useAuth app
11
+ - backend/start.sh -> uvicorn main:app (the real backend)
12
+
13
+ Runs from either build stage: it patches whichever target exists and prints
14
+ SKIP for the other (idempotent, re-runnable).
15
+ """
16
+
17
+ import os
18
+
19
+ FRONTEND_APP = r"""import { Box } from '@mui/material';
20
+ import AppLayout from '@/components/Layout/AppLayout';
21
+ import { useAuth } from '@/hooks/useAuth';
22
+
23
+ function App() {
24
+ // Non-blocking auth check -- fires in background, updates store when done.
25
+ // If auth fails later, apiFetch redirects to /auth/login.
26
+ useAuth();
27
+
28
+ return (
29
+ <Box sx={{ height: '100vh', display: 'flex' }}>
30
+ <AppLayout />
31
+ </Box>
32
+ );
33
+ }
34
+
35
+ export default App;
36
+ """
37
+
38
+ BACKEND_START = r"""#!/bin/bash
39
+ # Entrypoint for HF Spaces dev mode compatibility.
40
+ # Dev mode spawns CMD multiple times simultaneously on restart.
41
+ # Only the first instance can bind port 7860 - the rest must exit
42
+ # with code 0 so the dev mode daemon doesn't mark the app as crashed.
43
+
44
+ # Run uvicorn; if it fails due to port conflict, exit cleanly.
45
+ uvicorn main:app --host 0.0.0.0 --port 7860
46
+ EXIT_CODE=$?
47
+
48
+ if [ $EXIT_CODE -ne 0 ]; then
49
+ # Check if this was a port-in-use failure (another instance already running)
50
+ echo "uvicorn exited with code $EXIT_CODE, exiting gracefully."
51
+ exit 0
52
+ fi
53
+ """
54
+
55
+
56
+ def _write(path: str, content: str, executable: bool = False) -> bool:
57
+ if not os.path.exists(path):
58
+ return False
59
+ with open(path, "w", encoding="utf-8") as f:
60
+ f.write(content)
61
+ if executable:
62
+ os.chmod(path, 0o755)
63
+ return True
64
+
65
+
66
+ changed = False
67
+
68
+ written = _write("/source/frontend/src/App.tsx", FRONTEND_APP)
69
+ if written:
70
+ print("OK: restored /source/frontend/src/App.tsx (full AppLayout app)")
71
+ changed = True
72
+ else:
73
+ print("SKIP: /source/frontend/src/App.tsx not present (backend stage?)")
74
+
75
+ written = _write("/app/backend/start.sh", BACKEND_START, executable=True)
76
+ if written:
77
+ print("OK: restored /app/backend/start.sh (uvicorn main:app)")
78
+ changed = True
79
+ else:
80
+ print("SKIP: /app/backend/start.sh not present (frontend stage?)")
81
+
82
+ if not changed:
83
+ raise SystemExit("FAIL: neither target file found - unexpected layout")
84
+ print("OK: full-app restore done")