Spaces:
Runtime error
Runtime error
Upload main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# main.py 核心片段
|
| 2 |
+
@app.route('/file/<path:filename>')
|
| 3 |
+
def get_image_file(filename):
|
| 4 |
+
# 构造真实的 HF 地址
|
| 5 |
+
url = f"https://huggingface.co/datasets/{DATASET_NAME}/resolve/main/{filename}"
|
| 6 |
+
|
| 7 |
+
# 带着你的 Token 去请求,这就相当于有了“钥匙”
|
| 8 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 9 |
+
|
| 10 |
+
# 流式转发数据,不占用服务器内存
|
| 11 |
+
r = requests.get(url, headers=headers, stream=True)
|
| 12 |
+
return Response(r.iter_content(chunk_size=1024),
|
| 13 |
+
content_type=r.headers.get('Content-Type'))
|