Eluza133 commited on
Commit
bfc0cc7
·
verified ·
1 Parent(s): 09e98b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -730,11 +730,16 @@ def download_tma(file_id):
730
  if not hf_path:
731
  return Response("Ошибка: Путь к файлу не найден.", status=500)
732
 
733
- file_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
- r = requests.get(file_url, headers=req_headers, stream=True)
 
 
 
 
 
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
- file_url = f"https://huggingface.co/datasets/{REPO_ID}/resolve/main/{quote(hf_path)}?download=true"
769
  try:
770
- r = requests.get(file_url, headers=req_headers, stream=True)
 
 
 
 
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: