Spaces:
Runtime error
Runtime error
Fix CLIP BPE vocab download: derive path without importing the broken maskclip package
Browse files
app.py
CHANGED
|
@@ -42,15 +42,24 @@ def _ensure_featup():
|
|
| 42 |
def _ensure_clip_bpe_vocab():
|
| 43 |
"""FeatUp's maskclip tokenizer expects `bpe_simple_vocab_16e6.txt.gz` to
|
| 44 |
sit next to `simple_tokenizer.py`, but the file isn't shipped in the
|
| 45 |
-
FeatUp package. Download it from OpenAI's CLIP repo if missing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
import urllib.request
|
| 47 |
-
import featup
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
if os.path.isfile(bpe_path):
|
| 51 |
return
|
| 52 |
url = "https://github.com/openai/CLIP/raw/main/clip/bpe_simple_vocab_16e6.txt.gz"
|
| 53 |
print(f"[sab3r] Downloading CLIP BPE vocab to {bpe_path}")
|
|
|
|
| 54 |
urllib.request.urlretrieve(url, bpe_path)
|
| 55 |
|
| 56 |
|
|
|
|
| 42 |
def _ensure_clip_bpe_vocab():
|
| 43 |
"""FeatUp's maskclip tokenizer expects `bpe_simple_vocab_16e6.txt.gz` to
|
| 44 |
sit next to `simple_tokenizer.py`, but the file isn't shipped in the
|
| 45 |
+
FeatUp package. Download it from OpenAI's CLIP repo if missing.
|
| 46 |
+
|
| 47 |
+
We must NOT `import featup.featurizers.maskclip` to find the path — that
|
| 48 |
+
package's `__init__.py` runs the tokenizer constructor which will raise
|
| 49 |
+
the very FileNotFoundError we're trying to prevent. Instead import just
|
| 50 |
+
the top-level `featup` package and derive the maskclip directory.
|
| 51 |
+
"""
|
| 52 |
import urllib.request
|
| 53 |
+
import featup # top-level only, does not trigger maskclip chain
|
| 54 |
+
maskclip_dir = os.path.join(
|
| 55 |
+
os.path.dirname(featup.__file__), "featurizers", "maskclip"
|
| 56 |
+
)
|
| 57 |
+
bpe_path = os.path.join(maskclip_dir, "bpe_simple_vocab_16e6.txt.gz")
|
| 58 |
if os.path.isfile(bpe_path):
|
| 59 |
return
|
| 60 |
url = "https://github.com/openai/CLIP/raw/main/clip/bpe_simple_vocab_16e6.txt.gz"
|
| 61 |
print(f"[sab3r] Downloading CLIP BPE vocab to {bpe_path}")
|
| 62 |
+
os.makedirs(maskclip_dir, exist_ok=True)
|
| 63 |
urllib.request.urlretrieve(url, bpe_path)
|
| 64 |
|
| 65 |
|