ming commited on
Commit
c7cef80
·
1 Parent(s): bf6cabf

fix(spaces): add FastAPI root_path for HF proxy, ensure 0.0.0.0:7860, verify v2 paths

Browse files

- Make app proxy-aware via HF_SPACE_ROOT_PATH
- Provide __main__ uvicorn runner on 0.0.0.0:7860
- Clarify v2 router mount to avoid double prefixes
- Add test script for /health, /docs, and /api/v2/summarize/stream

Files changed (2) hide show
  1. app/main.py +10 -0
  2. scripts/test_endpoints.sh +15 -0
app/main.py CHANGED
@@ -1,6 +1,7 @@
1
  """
2
  Main FastAPI application for text summarizer backend.
3
  """
 
4
  import time
5
  from fastapi import FastAPI
6
  from fastapi.middleware.cors import CORSMiddleware
@@ -26,6 +27,8 @@ app = FastAPI(
26
  version="2.0.0",
27
  docs_url="/docs",
28
  redoc_url="/redoc",
 
 
29
  )
30
 
31
  # Add CORS middleware
@@ -152,3 +155,10 @@ async def debug_config():
152
  "enable_v1_warmup": settings.enable_v1_warmup,
153
  "enable_v2_warmup": settings.enable_v2_warmup
154
  }
 
 
 
 
 
 
 
 
1
  """
2
  Main FastAPI application for text summarizer backend.
3
  """
4
+ import os
5
  import time
6
  from fastapi import FastAPI
7
  from fastapi.middleware.cors import CORSMiddleware
 
27
  version="2.0.0",
28
  docs_url="/docs",
29
  redoc_url="/redoc",
30
+ # Make app aware of reverse-proxy prefix used by HF Spaces (if any)
31
+ root_path=os.getenv("HF_SPACE_ROOT_PATH", ""),
32
  )
33
 
34
  # Add CORS middleware
 
155
  "enable_v1_warmup": settings.enable_v1_warmup,
156
  "enable_v2_warmup": settings.enable_v2_warmup
157
  }
158
+
159
+
160
+ if __name__ == "__main__":
161
+ # Local/dev runner. On HF Spaces, the platform will spawn uvicorn for main:app,
162
+ # but this keeps behavior consistent if launched manually.
163
+ import uvicorn
164
+ uvicorn.run("app.main:app", host="0.0.0.0", port=7860, reload=False)
scripts/test_endpoints.sh ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ SPACE_URL="${1:?Usage: ./scripts/test_endpoints.sh https://<space>.hf.space}"
5
+
6
+ echo "==> Testing $SPACE_URL/health"
7
+ curl -i "$SPACE_URL/health" || true
8
+
9
+ echo "==> Testing $SPACE_URL/docs"
10
+ curl -i "$SPACE_URL/docs" || true
11
+
12
+ echo "==> Testing $SPACE_URL/api/v2/summarize/stream"
13
+ curl -i -X POST "$SPACE_URL/api/v2/summarize/stream" \
14
+ -H "content-type: application/json" \
15
+ -d '{"text":"This is a test to verify the V2 endpoint responds externally.","max_tokens":50}' || true