Vincent Wu
commited on
Commit
•
45c2f2e
1
Parent(s):
b14c96d
Add candidate number
Browse files
app.py
CHANGED
@@ -5,8 +5,10 @@ model_name = "BAAI/bge-large-zh-v1.5"
|
|
5 |
model = SentenceTransformer(model_name, device="cpu")
|
6 |
|
7 |
|
8 |
-
def cal_sim(
|
9 |
-
|
|
|
|
|
10 |
cand_list = [cand for cand in cand_list if cand]
|
11 |
embeddings_1 = model.encode([intent], normalize_embeddings=True)
|
12 |
embeddings_2 = model.encode(cand_list, normalize_embeddings=True)
|
@@ -18,15 +20,17 @@ def cal_sim(intent, cand1, cand2, cand3, cand4, cand5):
|
|
18 |
sim_output[i] = float(sim)
|
19 |
return sim_output
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
31 |
if __name__ == "__main__":
|
32 |
demo.launch(share=True, debug=True)
|
|
|
5 |
model = SentenceTransformer(model_name, device="cpu")
|
6 |
|
7 |
|
8 |
+
def cal_sim(*args):
|
9 |
+
intent = args[0]
|
10 |
+
cand_list = args[1:]
|
11 |
+
# cand_list = [cand1, cand2, cand3, cand4, cand5]
|
12 |
cand_list = [cand for cand in cand_list if cand]
|
13 |
embeddings_1 = model.encode([intent], normalize_embeddings=True)
|
14 |
embeddings_2 = model.encode(cand_list, normalize_embeddings=True)
|
|
|
20 |
sim_output[i] = float(sim)
|
21 |
return sim_output
|
22 |
|
23 |
+
|
24 |
+
inputs = [
|
25 |
+
gr.components.Textbox(label="User query"),
|
26 |
+
]
|
27 |
+
candidate_box = [gr.components.Textbox(label=f"candidate_{i}") for i in range(30)]
|
28 |
+
inputs.extend(candidate_box)
|
29 |
+
demo = gr.Interface(
|
30 |
+
fn=cal_sim,
|
31 |
+
inputs=inputs,
|
32 |
+
outputs=gr.components.Label(),
|
33 |
+
)
|
34 |
+
|
35 |
if __name__ == "__main__":
|
36 |
demo.launch(share=True, debug=True)
|