Spaces:
Runtime error
Runtime error
fix
Browse files
app.py
CHANGED
@@ -8,21 +8,31 @@ from sentence_transformers.util import semantic_search
|
|
8 |
|
9 |
|
10 |
st.title("VitB32 Bert Ko Small Clip Test")
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
)
|
|
|
|
|
|
|
16 |
|
17 |
info = pd.read_csv("info.csv")
|
18 |
with open("img_id.pkl", "rb") as f:
|
19 |
img_id = pickle.load(f)
|
20 |
img_emb = np.load("img_emb.npy")
|
21 |
|
22 |
-
text = st.text_input("Input Text")
|
23 |
tokens = processor(text=text, return_tensors="pt")
|
24 |
-
text_emb = model.get_text_features(**tokens)
|
25 |
|
26 |
-
|
|
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
|
10 |
st.title("VitB32 Bert Ko Small Clip Test")
|
11 |
+
st.markdown("Unsplash data์์ ์
๋ ฅ ํ
์คํธ์ ๊ฐ์ฅ ์ ์ฌํ ์ด๋ฏธ์ง๋ฅผ ๊ฒ์ํฉ๋๋ค.")
|
12 |
|
13 |
+
with st.spinner("Loading model..."):
|
14 |
+
model = VisionTextDualEncoderModel.from_pretrained(
|
15 |
+
"Bingsu/vitB32_bert_ko_small_clip"
|
16 |
+
)
|
17 |
+
processor = VisionTextDualEncoderProcessor.from_pretrained(
|
18 |
+
"Bingsu/vitB32_bert_ko_small_clip"
|
19 |
+
)
|
20 |
|
21 |
info = pd.read_csv("info.csv")
|
22 |
with open("img_id.pkl", "rb") as f:
|
23 |
img_id = pickle.load(f)
|
24 |
img_emb = np.load("img_emb.npy")
|
25 |
|
26 |
+
text = st.text_input("Input Text", value="๊ฒ์ ๊ณ ์์ด")
|
27 |
tokens = processor(text=text, return_tensors="pt")
|
|
|
28 |
|
29 |
+
with st.spinner("Predicting..."):
|
30 |
+
text_emb = model.get_text_features(**tokens)
|
31 |
|
32 |
+
result = semantic_search(text_emb, img_emb, top_k=6)[0]
|
33 |
+
|
34 |
+
columns = st.columns(3) + st.columns(3)
|
35 |
+
for i, col in enumerate(columns):
|
36 |
+
photo_id = img_id[result[i]["corpus_id"]]
|
37 |
+
img_url = info.loc[info["photo_id"] == photo_id, "photo_image_url"].values[0]
|
38 |
+
col.image(img_url, use_column_width=True)
|