Wind-xixi commited on
Commit
e1a87f2
·
verified ·
1 Parent(s): 09c314a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI, File, UploadFile
2
  from fastapi.responses import JSONResponse
3
  import uvicorn
4
  from predictor import Predictor
 
5
 
6
  # 创建 FastAPI 应用
7
  app = FastAPI()
@@ -30,7 +31,6 @@ async def evaluate_file(file: UploadFile = File(...)):
30
 
31
 
32
  if __name__ == "__main__":
33
- uvicorn.run("app:app", host="0.0.0.0", port=7860)
34
-
35
-
36
-
 
2
  from fastapi.responses import JSONResponse
3
  import uvicorn
4
  from predictor import Predictor
5
+ import os
6
 
7
  # 创建 FastAPI 应用
8
  app = FastAPI()
 
31
 
32
 
33
  if __name__ == "__main__":
34
+ # Hugging Face Spaces 会设置环境变量 HF_SPACE
35
+ port = int(os.getenv("PORT", 7860)) # HF Spaces 会传 PORT
36
+ uvicorn.run("app:app", host="0.0.0.0", port=port)