Spaces:
Sleeping
Sleeping
fix: 下载地址
Browse files
api.py
CHANGED
@@ -42,7 +42,7 @@ if not os.path.exists(UPLOAD_DIRECTORY):
|
|
42 |
|
43 |
def download_file(url: str):
|
44 |
headers = {"Authorization": f"Bearer {HUGGINGFACE_API_TOKEN}"}
|
45 |
-
response = requests.get(url, headers=headers, stream=True)
|
46 |
# with requests.get(url, stream=True,headers=headers) as response:
|
47 |
# for chunk in response.iter_content(chunk_size=1024): # 每次读取 1KB
|
48 |
# if chunk:
|
@@ -84,7 +84,7 @@ async def upload_file(userId: str, modelId: str, filename: str, file: UploadFile
|
|
84 |
|
85 |
@router.get("/download/{userId}/{filename}")
|
86 |
def download(userId: str, filename: str):
|
87 |
-
pathInRepo = f"{
|
88 |
response = download_file(pathInRepo)
|
89 |
# 创建流式响应
|
90 |
return StreamingResponse(response.iter_content(chunk_size=1024),
|
|
|
42 |
|
43 |
def download_file(url: str):
|
44 |
headers = {"Authorization": f"Bearer {HUGGINGFACE_API_TOKEN}"}
|
45 |
+
response = requests.get(f"https://huggingface.co/{REPO_ID}/resolve/main/{url}?download=true", headers=headers, stream=True)
|
46 |
# with requests.get(url, stream=True,headers=headers) as response:
|
47 |
# for chunk in response.iter_content(chunk_size=1024): # 每次读取 1KB
|
48 |
# if chunk:
|
|
|
84 |
|
85 |
@router.get("/download/{userId}/{filename}")
|
86 |
def download(userId: str, filename: str):
|
87 |
+
pathInRepo = f"{userId}/{filename}"
|
88 |
response = download_file(pathInRepo)
|
89 |
# 创建流式响应
|
90 |
return StreamingResponse(response.iter_content(chunk_size=1024),
|