code: sync from git
Browse files- code/hfeco/hub.py +10 -1
code/hfeco/hub.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"""Thin, retrying wrappers around the Hugging Face Hub API."""
|
| 2 |
import random
|
|
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
import httpx
|
|
@@ -54,7 +55,15 @@ def full_text(q, kind, page=100, cap=5000):
|
|
| 54 |
params={"q": q, "type": kind, "limit": page, "skip": skip}, headers=h, timeout=60)
|
| 55 |
r.raise_for_status() # inside retry, so a 5xx/429 from the search backend is retried
|
| 56 |
return r
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
hits = r.json().get("hits", [])
|
| 59 |
if not hits:
|
| 60 |
break
|
|
|
|
| 1 |
"""Thin, retrying wrappers around the Hugging Face Hub API."""
|
| 2 |
import random
|
| 3 |
+
import sys
|
| 4 |
import time
|
| 5 |
|
| 6 |
import httpx
|
|
|
|
| 55 |
params={"q": q, "type": kind, "limit": page, "skip": skip}, headers=h, timeout=60)
|
| 56 |
r.raise_for_status() # inside retry, so a 5xx/429 from the search backend is retried
|
| 57 |
return r
|
| 58 |
+
try:
|
| 59 |
+
r = retry(get)
|
| 60 |
+
except requests.HTTPError as e:
|
| 61 |
+
# Deep pages of the search backend can time out for good; keep what the earlier
|
| 62 |
+
# pages found rather than failing the day's run.
|
| 63 |
+
if e.response is None or e.response.status_code < 500:
|
| 64 |
+
raise
|
| 65 |
+
print(f"full-text {kind} {q!r}: stopped at skip={skip} ({e.response.status_code})", file=sys.stderr)
|
| 66 |
+
break
|
| 67 |
hits = r.json().get("hits", [])
|
| 68 |
if not hits:
|
| 69 |
break
|