Tataaicoltd commited on
Commit
4e003e4
·
verified ·
1 Parent(s): 4c92799

fix: admin uses tataaicoltd-api.hf.space as backend on HF

Browse files
Files changed (3) hide show
  1. Dockerfile.api +15 -0
  2. admin/js/api.js +9 -1
  3. backend/main.py +2 -1
Dockerfile.api ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Copy backend only (no admin frontend)
6
+ COPY backend/ ./backend/
7
+
8
+ # Install dependencies
9
+ RUN pip install --no-cache-dir -r backend/requirements.txt
10
+
11
+ EXPOSE 7860
12
+
13
+ # Run from backend dir so relative imports resolve correctly
14
+ WORKDIR /app/backend
15
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
admin/js/api.js CHANGED
@@ -1,5 +1,13 @@
1
  // API configuration
2
- const API_BASE_URL = location.hostname === 'localhost' ? 'http://localhost:4000/api' : '/api';
 
 
 
 
 
 
 
 
3
 
4
  class ApiClient {
5
  constructor(baseUrl = API_BASE_URL) {
 
1
  // API configuration
2
+ const API_BASE_URL = (() => {
3
+ if (location.hostname === 'localhost' || location.hostname === '127.0.0.1') {
4
+ return 'http://localhost:4000/api';
5
+ }
6
+ if (location.hostname.includes('.hf.space')) {
7
+ return 'https://tataaicoltd-api.hf.space/api';
8
+ }
9
+ return '/api';
10
+ })();
11
 
12
  class ApiClient {
13
  constructor(baseUrl = API_BASE_URL) {
backend/main.py CHANGED
@@ -496,7 +496,8 @@ async def search_nearest(payload: dict = Body(...)):
496
 
497
  # Serve admin static files (must be mounted last, after all API routes)
498
  _admin_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'admin')
499
- app.mount("/", StaticFiles(directory=_admin_dir, html=True), name="admin")
 
500
 
501
 
502
  if __name__ == '__main__':
 
496
 
497
  # Serve admin static files (must be mounted last, after all API routes)
498
  _admin_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'admin')
499
+ if os.path.isdir(_admin_dir):
500
+ app.mount("/", StaticFiles(directory=_admin_dir, html=True), name="admin")
501
 
502
 
503
  if __name__ == '__main__':