Bingsu commited on
Commit
5834f42
โ€ข
1 Parent(s): bf3fe47
Files changed (1) hide show
  1. app.py +18 -8
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
- model = VisionTextDualEncoderModel.from_pretrained("Bingsu/vitB32_bert_ko_small_clip")
13
- processor = VisionTextDualEncoderProcessor.from_pretrained(
14
- "Bingsu/vitB32_bert_ko_small_clip"
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
- result = semantic_search(text_emb, img_emb, top_k=6)
 
27
 
28
- st.write(result)
 
 
 
 
 
 
 
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)