Spaces:
Sleeping
Sleeping
ForStream Claude Opus 4.8 commited on
Commit ·
76adee7
1
Parent(s): 2ba4c4a
Fix /api/download 404: LFS 파일 런타임 fetch fallback
Browse filesHF Docker 빌드가 assets LFS 파일을 빌드 컨텍스트에 실제 내용으로 넣지 않아
COPY assets/ 후에도 /app/assets/*.pdf,png 부재 → /api/download 404 (빌드 RUNNING인데도).
download 핸들러에 파일 부재 시 huggingface_hub.hf_hub_download로 Space 레포에서
런타임 fetch하는 fallback 추가(HF_TOKEN). Dockerfile CACHE_BUST v7.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Dockerfile +1 -1
- api/main.py +11 -1
Dockerfile
CHANGED
|
@@ -39,7 +39,7 @@ RUN pip install --upgrade pip && pip install -r /app/api/requirements.txt
|
|
| 39 |
|
| 40 |
# 코드 (rag_engine·semantic_search 등 active/code의 핵심 모듈)
|
| 41 |
# 캐시 무효화용 ARG (commit SHA 다르면 캐시 무효화)
|
| 42 |
-
ARG CACHE_BUST=
|
| 43 |
COPY code/ /app/code/
|
| 44 |
# 백엔드
|
| 45 |
COPY api/ /app/api/
|
|
|
|
| 39 |
|
| 40 |
# 코드 (rag_engine·semantic_search 등 active/code의 핵심 모듈)
|
| 41 |
# 캐시 무효화용 ARG (commit SHA 다르면 캐시 무효화)
|
| 42 |
+
ARG CACHE_BUST=v7
|
| 43 |
COPY code/ /app/code/
|
| 44 |
# 백엔드
|
| 45 |
COPY api/ /app/api/
|
api/main.py
CHANGED
|
@@ -228,7 +228,17 @@ def download(kind: str):
|
|
| 228 |
raise HTTPException(404, f"unknown kind: {kind}")
|
| 229 |
path, filename, media_type = path_map[kind]
|
| 230 |
if not path.exists():
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
return FileResponse(str(path), filename=filename, media_type=media_type)
|
| 233 |
|
| 234 |
|
|
|
|
| 228 |
raise HTTPException(404, f"unknown kind: {kind}")
|
| 229 |
path, filename, media_type = path_map[kind]
|
| 230 |
if not path.exists():
|
| 231 |
+
# HF Docker 빌드는 LFS 파일(assets)을 빌드 컨텍스트에 실제 내용으로 넣지 않을 수 있다.
|
| 232 |
+
# 이 경우 런타임에 Space 레포에서 직접 fetch (HF_TOKEN). 빌드/LFS smudge 의존 제거.
|
| 233 |
+
try:
|
| 234 |
+
from huggingface_hub import hf_hub_download
|
| 235 |
+
fetched = hf_hub_download(
|
| 236 |
+
repo_id="ForStream/ontology-prototype", repo_type="space",
|
| 237 |
+
filename=f"assets/{path.name}", token=os.environ.get("HF_TOKEN") or None,
|
| 238 |
+
)
|
| 239 |
+
return FileResponse(fetched, filename=filename, media_type=media_type)
|
| 240 |
+
except Exception as e:
|
| 241 |
+
raise HTTPException(404, f"file not found: {path} (런타임 fetch 실패: {e})")
|
| 242 |
return FileResponse(str(path), filename=filename, media_type=media_type)
|
| 243 |
|
| 244 |
|