Commit
·
d06266d
1
Parent(s):
6f3b24c
Update and trim dependencies, isort imports
Browse files- app.py +22 -13
- requirements.txt +0 -1
app.py
CHANGED
@@ -1,31 +1,38 @@
|
|
1 |
import json
|
2 |
import os
|
3 |
from collections import defaultdict
|
4 |
-
from typing import
|
5 |
|
6 |
import faiss
|
7 |
import gradio as gr
|
8 |
import numpy as np
|
9 |
-
from
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
from hfutils.utils import TemporaryDirectory
|
14 |
-
from
|
15 |
from imgutils.utils import ts_lru_cache
|
|
|
16 |
|
17 |
from pools import quick_webp_pool
|
18 |
|
19 |
-
|
20 |
-
|
21 |
|
22 |
hf_fs = get_hf_fs()
|
23 |
hf_client = get_hf_client()
|
24 |
|
25 |
_DEFAULT_MODEL_NAME = 'SwinV2_v3_danbooru_8005009_4GB'
|
26 |
_ALL_MODEL_NAMES = [
|
27 |
-
os.path.dirname(os.path.relpath(path,
|
28 |
-
for path in hf_fs.glob(f'{
|
29 |
]
|
30 |
|
31 |
_SITE_CLS = {
|
@@ -97,17 +104,19 @@ def _get_index_info(repo_id: str, model_name: str):
|
|
97 |
|
98 |
|
99 |
def search(model_name: str, img_input, str_input: str, n_neighbours: int):
|
100 |
-
images_ids, knn_index = _get_index_info(
|
101 |
|
102 |
if str_input == "":
|
103 |
-
embeddings = siglip.
|
104 |
img_input,
|
|
|
105 |
model_name="smilingwolf/siglip_swinv2_base_2025_02_22_18h56m54s",
|
106 |
fmt="embeddings",
|
107 |
)
|
108 |
else:
|
109 |
-
embeddings = siglip.
|
110 |
str_input,
|
|
|
111 |
model_name="smilingwolf/siglip_swinv2_base_2025_02_22_18h56m54s",
|
112 |
fmt="embeddings",
|
113 |
)
|
|
|
1 |
import json
|
2 |
import os
|
3 |
from collections import defaultdict
|
4 |
+
from typing import Dict, List
|
5 |
|
6 |
import faiss
|
7 |
import gradio as gr
|
8 |
import numpy as np
|
9 |
+
from cheesechaser.datapool import (
|
10 |
+
AnimePicturesWebpDataPool,
|
11 |
+
DanbooruNewestWebpDataPool,
|
12 |
+
GelbooruWebpDataPool,
|
13 |
+
KonachanWebpDataPool,
|
14 |
+
Rule34WebpDataPool,
|
15 |
+
YandeWebpDataPool,
|
16 |
+
ZerochanWebpDataPool,
|
17 |
+
)
|
18 |
+
from hfutils.operate import get_hf_client, get_hf_fs
|
19 |
from hfutils.utils import TemporaryDirectory
|
20 |
+
from imgutils.generic import siglip
|
21 |
from imgutils.utils import ts_lru_cache
|
22 |
+
from PIL import Image
|
23 |
|
24 |
from pools import quick_webp_pool
|
25 |
|
26 |
+
_SIGLIP_REPO_ID = "deepghs/siglip_beta"
|
27 |
+
_INDEX_REPO_ID = 'deepghs/anime_sites_indices'
|
28 |
|
29 |
hf_fs = get_hf_fs()
|
30 |
hf_client = get_hf_client()
|
31 |
|
32 |
_DEFAULT_MODEL_NAME = 'SwinV2_v3_danbooru_8005009_4GB'
|
33 |
_ALL_MODEL_NAMES = [
|
34 |
+
os.path.dirname(os.path.relpath(path, _INDEX_REPO_ID))
|
35 |
+
for path in hf_fs.glob(f'{_INDEX_REPO_ID}/*/knn.index')
|
36 |
]
|
37 |
|
38 |
_SITE_CLS = {
|
|
|
104 |
|
105 |
|
106 |
def search(model_name: str, img_input, str_input: str, n_neighbours: int):
|
107 |
+
images_ids, knn_index = _get_index_info(_INDEX_REPO_ID, model_name)
|
108 |
|
109 |
if str_input == "":
|
110 |
+
embeddings = siglip.siglip_image_encode(
|
111 |
img_input,
|
112 |
+
repo_id=_SIGLIP_REPO_ID,
|
113 |
model_name="smilingwolf/siglip_swinv2_base_2025_02_22_18h56m54s",
|
114 |
fmt="embeddings",
|
115 |
)
|
116 |
else:
|
117 |
+
embeddings = siglip.siglip_text_encode(
|
118 |
str_input,
|
119 |
+
repo_id=_SIGLIP_REPO_ID,
|
120 |
model_name="smilingwolf/siglip_swinv2_base_2025_02_22_18h56m54s",
|
121 |
fmt="embeddings",
|
122 |
)
|
requirements.txt
CHANGED
@@ -3,5 +3,4 @@ faiss-cpu
|
|
3 |
dghs-imgutils
|
4 |
onnxruntime
|
5 |
cheesechaser>=0.1.6
|
6 |
-
dghs-realutils>=0.1.0
|
7 |
gradio
|
|
|
3 |
dghs-imgutils
|
4 |
onnxruntime
|
5 |
cheesechaser>=0.1.6
|
|
|
6 |
gradio
|