Update app.py
Browse files
app.py
CHANGED
|
@@ -730,11 +730,16 @@ def download_tma(file_id):
|
|
| 730 |
if not hf_path:
|
| 731 |
return Response("Ошибка: Путь к файлу не найден.", status=500)
|
| 732 |
|
| 733 |
-
|
| 734 |
try:
|
| 735 |
req_headers = {}
|
| 736 |
if HF_TOKEN_READ: req_headers["authorization"] = f"Bearer {HF_TOKEN_READ}"
|
| 737 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
r.raise_for_status()
|
| 739 |
|
| 740 |
resp = Response(r.iter_content(chunk_size=8192), mimetype='application/octet-stream')
|
|
@@ -765,9 +770,13 @@ def batch_download_tma():
|
|
| 765 |
if file_node and file_node.get('path'):
|
| 766 |
hf_path = file_node['path']
|
| 767 |
original_filename = file_node.get('original_filename', file_id)
|
| 768 |
-
|
| 769 |
try:
|
| 770 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 771 |
r.raise_for_status()
|
| 772 |
zf.writestr(original_filename, r.content)
|
| 773 |
except Exception as e:
|
|
|
|
| 730 |
if not hf_path:
|
| 731 |
return Response("Ошибка: Путь к файлу не найден.", status=500)
|
| 732 |
|
| 733 |
+
initial_url = f"https://huggingface.co/datasets/{REPO_ID}/resolve/main/{quote(hf_path)}?download=true"
|
| 734 |
try:
|
| 735 |
req_headers = {}
|
| 736 |
if HF_TOKEN_READ: req_headers["authorization"] = f"Bearer {HF_TOKEN_READ}"
|
| 737 |
+
|
| 738 |
+
head_r = requests.head(initial_url, headers=req_headers, allow_redirects=True)
|
| 739 |
+
head_r.raise_for_status()
|
| 740 |
+
final_url = head_r.url
|
| 741 |
+
|
| 742 |
+
r = requests.get(final_url, stream=True)
|
| 743 |
r.raise_for_status()
|
| 744 |
|
| 745 |
resp = Response(r.iter_content(chunk_size=8192), mimetype='application/octet-stream')
|
|
|
|
| 770 |
if file_node and file_node.get('path'):
|
| 771 |
hf_path = file_node['path']
|
| 772 |
original_filename = file_node.get('original_filename', file_id)
|
| 773 |
+
initial_url = f"https://huggingface.co/datasets/{REPO_ID}/resolve/main/{quote(hf_path)}?download=true"
|
| 774 |
try:
|
| 775 |
+
head_r = requests.head(initial_url, headers=req_headers, allow_redirects=True)
|
| 776 |
+
head_r.raise_for_status()
|
| 777 |
+
final_url = head_r.url
|
| 778 |
+
|
| 779 |
+
r = requests.get(final_url)
|
| 780 |
r.raise_for_status()
|
| 781 |
zf.writestr(original_filename, r.content)
|
| 782 |
except Exception as e:
|