Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +31 -7
__pycache__/app.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
|
app.py
CHANGED
|
@@ -28,9 +28,21 @@ DROP_WORDS = {
|
|
| 28 |
"image", "photo", "picture", "view", "scene", "background", "foreground",
|
| 29 |
"left", "right", "top", "bottom", "front", "back", "side", "area", "part",
|
| 30 |
"visible", "large", "small", "several", "multiple", "many", "some",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
CAPTION_SPLIT = re.compile(
|
| 33 |
-
r"[,.;:]|\\bwith\\b|\\band\\b|\\bnext to\\b|\\bin front of\\b|\\bbehind\\b|\\bon\\b|\\balong\\b|\\bnear\\b",
|
| 34 |
flags=re.IGNORECASE,
|
| 35 |
)
|
| 36 |
|
|
@@ -39,12 +51,23 @@ def _clean_label(value: str) -> str:
|
|
| 39 |
text = str(value).strip().lower()
|
| 40 |
text = re.sub(r"[_/\\-]+", " ", text)
|
| 41 |
text = re.sub(r"[^a-z0-9\\s]+", " ", text)
|
|
|
|
|
|
|
|
|
|
| 42 |
words = [w for w in text.split() if w and w not in DROP_WORDS]
|
| 43 |
if not words:
|
| 44 |
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
if len(words) > 5:
|
| 46 |
words = words[-5:]
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
def _labels_from_caption(text: str) -> list[str]:
|
|
@@ -54,12 +77,13 @@ def _labels_from_caption(text: str) -> list[str]:
|
|
| 54 |
if not clean:
|
| 55 |
continue
|
| 56 |
words = clean.split()
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
| 61 |
candidate = _clean_label(candidate)
|
| 62 |
-
if candidate and len(candidate) > 2:
|
| 63 |
labels.append(candidate)
|
| 64 |
break
|
| 65 |
return labels
|
|
|
|
| 28 |
"image", "photo", "picture", "view", "scene", "background", "foreground",
|
| 29 |
"left", "right", "top", "bottom", "front", "back", "side", "area", "part",
|
| 30 |
"visible", "large", "small", "several", "multiple", "many", "some",
|
| 31 |
+
"is", "are", "was", "were", "be", "being", "been", "appears", "appear",
|
| 32 |
+
"of", "in", "it", "its", "to", "for", "by", "as", "at", "from", "into",
|
| 33 |
+
"parked", "parking", "surrounded", "including", "taken", "shining",
|
| 34 |
+
"brightly", "different", "models", "colors", "color", "angle", "high",
|
| 35 |
+
"panoramic", "modern", "curved", "few", "blue", "red", "white",
|
| 36 |
+
}
|
| 37 |
+
KEEP_PHRASES = {
|
| 38 |
+
"parking lot",
|
| 39 |
+
}
|
| 40 |
+
DROP_LABELS = {
|
| 41 |
+
"roof", "floor", "floors", "balcony", "balconies", "sun", "cloud", "clouds",
|
| 42 |
+
"sky", "brightly", "angle", "high angle",
|
| 43 |
}
|
| 44 |
CAPTION_SPLIT = re.compile(
|
| 45 |
+
r"[,.;:]|\\bwith\\b|\\band\\b|\\bnext to\\b|\\bin front of\\b|\\bbehind\\b|\\bon\\b|\\balong\\b|\\bnear\\b|\\bsurrounded by\\b",
|
| 46 |
flags=re.IGNORECASE,
|
| 47 |
)
|
| 48 |
|
|
|
|
| 51 |
text = str(value).strip().lower()
|
| 52 |
text = re.sub(r"[_/\\-]+", " ", text)
|
| 53 |
text = re.sub(r"[^a-z0-9\\s]+", " ", text)
|
| 54 |
+
for phrase in KEEP_PHRASES:
|
| 55 |
+
if phrase in text:
|
| 56 |
+
return phrase
|
| 57 |
words = [w for w in text.split() if w and w not in DROP_WORDS]
|
| 58 |
if not words:
|
| 59 |
return ""
|
| 60 |
+
if len(words) == 1:
|
| 61 |
+
word = words[0]
|
| 62 |
+
if len(word) > 3 and word.endswith("ies"):
|
| 63 |
+
word = word[:-3] + "y"
|
| 64 |
+
elif len(word) > 3 and word.endswith("s") and not word.endswith("ss"):
|
| 65 |
+
word = word[:-1]
|
| 66 |
+
words = [word]
|
| 67 |
if len(words) > 5:
|
| 68 |
words = words[-5:]
|
| 69 |
+
label = " ".join(words)
|
| 70 |
+
return "" if label in DROP_LABELS else label
|
| 71 |
|
| 72 |
|
| 73 |
def _labels_from_caption(text: str) -> list[str]:
|
|
|
|
| 77 |
if not clean:
|
| 78 |
continue
|
| 79 |
words = clean.split()
|
| 80 |
+
candidates = [clean]
|
| 81 |
+
if len(words) >= 3:
|
| 82 |
+
candidates.append(" ".join(words[-2:]))
|
| 83 |
+
candidates.append(words[-1])
|
| 84 |
+
for candidate in candidates:
|
| 85 |
candidate = _clean_label(candidate)
|
| 86 |
+
if candidate and len(candidate) > 2 and candidate not in labels:
|
| 87 |
labels.append(candidate)
|
| 88 |
break
|
| 89 |
return labels
|