Bhishaj9 commited on
Commit
276db66
·
1 Parent(s): 01692a4

fix: resolve HF Space restart - port mismatch, CORS, worker count, env vars

Browse files
Files changed (4) hide show
  1. Dockerfile +3 -1
  2. backend/config.py +2 -2
  3. backend/main.py +4 -3
  4. supervisord.conf +1 -1
Dockerfile CHANGED
@@ -64,8 +64,10 @@ USER 1000
64
 
65
  # Set Environment Variables
66
  ENV SEARXNG_SETTINGS_PATH=/app/searxng/settings.yml
67
- ENV SEARXNG_BASE_URL=http://localhost:8888/
68
  ENV BACKEND_URL=http://localhost:8000
 
 
69
  ENV PORT=3000
70
 
71
  EXPOSE 3000 8000 8888
 
64
 
65
  # Set Environment Variables
66
  ENV SEARXNG_SETTINGS_PATH=/app/searxng/settings.yml
67
+ ENV SEARXNG_BASE_URL=http://localhost:8888
68
  ENV BACKEND_URL=http://localhost:8000
69
+ ENV FRONTEND_URL=*
70
+ ENV SARVAM_API_KEY=""
71
  ENV PORT=3000
72
 
73
  EXPOSE 3000 8000 8888
backend/config.py CHANGED
@@ -15,12 +15,12 @@ class Settings(BaseSettings):
15
  SARVAM_SYNTH_MODEL: str = "sarvam-105b"
16
 
17
  # ── SearxNG ────────────────────────────────────────────────
18
- SEARXNG_BASE_URL: str = "http://localhost:8080"
19
  SEARCH_REGION_DEFAULT: str = "in-en"
20
  SEARCH_LANG_DEFAULT: str = "en"
21
 
22
  # ── Frontend ───────────────────────────────────────────────
23
- FRONTEND_URL: str = "http://localhost:3000"
24
 
25
  model_config = {
26
  "env_file": ".env",
 
15
  SARVAM_SYNTH_MODEL: str = "sarvam-105b"
16
 
17
  # ── SearxNG ────────────────────────────────────────────────
18
+ SEARXNG_BASE_URL: str = "http://localhost:8888"
19
  SEARCH_REGION_DEFAULT: str = "in-en"
20
  SEARCH_LANG_DEFAULT: str = "en"
21
 
22
  # ── Frontend ───────────────────────────────────────────────
23
+ FRONTEND_URL: str = "*"
24
 
25
  model_config = {
26
  "env_file": ".env",
backend/main.py CHANGED
@@ -26,11 +26,12 @@ app = FastAPI(
26
  version="0.4.0",
27
  )
28
 
29
- # CORS: allow frontend dev server
 
30
  app.add_middleware(
31
  CORSMiddleware,
32
- allow_origins=[settings.FRONTEND_URL],
33
- allow_credentials=True,
34
  allow_methods=["*"],
35
  allow_headers=["*"],
36
  )
 
26
  version="0.4.0",
27
  )
28
 
29
+ # CORS: allow frontend (wildcard for HF Spaces, specific URL for local dev)
30
+ _origins = ["*"] if settings.FRONTEND_URL == "*" else [settings.FRONTEND_URL]
31
  app.add_middleware(
32
  CORSMiddleware,
33
+ allow_origins=_origins,
34
+ allow_credentials=False if settings.FRONTEND_URL == "*" else True,
35
  allow_methods=["*"],
36
  allow_headers=["*"],
37
  )
supervisord.conf CHANGED
@@ -15,7 +15,7 @@ stderr_logfile=/dev/stderr
15
  stderr_logfile_maxbytes=0
16
 
17
  [program:backend]
18
- command=gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
19
  directory=/app/backend
20
  autostart=true
21
  autorestart=true
 
15
  stderr_logfile_maxbytes=0
16
 
17
  [program:backend]
18
+ command=gunicorn main:app --workers 2 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
19
  directory=/app/backend
20
  autostart=true
21
  autorestart=true