shelfgot commited on
Commit
6441bee
·
verified ·
1 Parent(s): a4d498a

Update predict.py

Browse files
Files changed (1) hide show
  1. predict.py +21 -4
predict.py CHANGED
@@ -29,21 +29,38 @@ def fetch_daf_texts(vercel_base_url: str, auth_token: str) -> list:
29
  print(f"Fetching daf texts from {url}...")
30
 
31
  try:
32
- # Include authentication token in header
33
  headers = {
34
  'x-auth-token': auth_token,
35
  'Content-Type': 'application/json'
36
  }
 
 
 
 
 
 
 
 
 
37
  response = requests.get(url, headers=headers, timeout=60)
38
  response.raise_for_status()
39
  data = response.json()
40
  print(f"Fetched {data.get('count', 0)} dafim")
41
  return data.get('dafim', [])
42
- except Exception as e:
43
- print(f"Error fetching daf texts: {e}")
44
  if hasattr(e, 'response') and e.response is not None:
45
  print(f"Response status: {e.response.status_code}")
46
- print(f"Response text: {e.response.text}")
 
 
 
 
 
 
 
 
 
47
  raise
48
 
49
  def text_to_sequence(text: str, word_to_idx: dict) -> list:
 
29
  print(f"Fetching daf texts from {url}...")
30
 
31
  try:
 
32
  headers = {
33
  'x-auth-token': auth_token,
34
  'Content-Type': 'application/json'
35
  }
36
+
37
+
38
+ vercel_bypass_token = os.getenv('VERCEL_BYPASS_TOKEN')
39
+ if vercel_bypass_token:
40
+
41
+ separator = '&' if '?' in url else '?'
42
+ url = f"{url}{separator}x-vercel-set-bypass-cookie=true&x-vercel-protection-bypass={vercel_bypass_token}"
43
+ print(f"Using Vercel bypass token for deployment protection")
44
+
45
  response = requests.get(url, headers=headers, timeout=60)
46
  response.raise_for_status()
47
  data = response.json()
48
  print(f"Fetched {data.get('count', 0)} dafim")
49
  return data.get('dafim', [])
50
+ except requests.exceptions.HTTPError as e:
51
+ print(f"HTTP Error fetching daf texts: {e}")
52
  if hasattr(e, 'response') and e.response is not None:
53
  print(f"Response status: {e.response.status_code}")
54
+ # Print first 500 chars of response for debugging
55
+ response_text = e.response.text[:500] if e.response.text else "No response text"
56
+ print(f"Response text (first 500 chars): {response_text}")
57
+ # Check if it's a deployment protection issue
58
+ if e.response.status_code == 401 and 'Authentication Required' in response_text:
59
+ print("ERROR: Deployment protection is blocking the request.")
60
+ print("Make sure VERCEL_BYPASS_TOKEN is set correctly in HF Space environment variables.")
61
+ raise
62
+ except Exception as e:
63
+ print(f"Error fetching daf texts: {e}")
64
  raise
65
 
66
  def text_to_sequence(text: str, word_to_idx: dict) -> list: