Spaces:
Runtime error
Runtime error
liuwei
commited on
Commit
•
285e2b7
1
Parent(s):
117517b
init
Browse files
app.py
CHANGED
@@ -34,12 +34,13 @@ def app():
|
|
34 |
button_generate = st.button("计算")
|
35 |
button_clear = st.button("清空")
|
36 |
|
37 |
-
def transformer(sentences):
|
38 |
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2', device="cpu")
|
39 |
source_emb = model.encode(source_text, convert_to_tensor=True)
|
40 |
sent_embs = model.encode(sentences, convert_to_tensor=True)
|
41 |
cos_sim = util.cos_sim(source_emb, sent_embs)
|
42 |
|
|
|
43 |
cosin_dict = {}
|
44 |
|
45 |
for i, cos in cos_sim[0]:
|
@@ -51,12 +52,16 @@ def app():
|
|
51 |
|
52 |
if button_generate:
|
53 |
# embeddings
|
54 |
-
embeddings = transformer(st.session_state.inputs)
|
55 |
|
56 |
# 显示生成的文本
|
57 |
st.write(embeddings)
|
58 |
#output_text.success(generated_text)
|
59 |
|
|
|
|
|
|
|
|
|
60 |
if button_clear:
|
61 |
st.session_state.inputs.clear()
|
62 |
del st.session_state["inputs"]
|
@@ -64,6 +69,8 @@ def app():
|
|
64 |
source_text = ''
|
65 |
st.experimental_rerun()
|
66 |
|
|
|
|
|
67 |
if __name__ == "__main__":
|
68 |
# 运行应用程序
|
69 |
app()
|
|
|
34 |
button_generate = st.button("计算")
|
35 |
button_clear = st.button("清空")
|
36 |
|
37 |
+
def transformer(source_text, sentences):
|
38 |
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2', device="cpu")
|
39 |
source_emb = model.encode(source_text, convert_to_tensor=True)
|
40 |
sent_embs = model.encode(sentences, convert_to_tensor=True)
|
41 |
cos_sim = util.cos_sim(source_emb, sent_embs)
|
42 |
|
43 |
+
st.write(cos_sim)
|
44 |
cosin_dict = {}
|
45 |
|
46 |
for i, cos in cos_sim[0]:
|
|
|
52 |
|
53 |
if button_generate:
|
54 |
# embeddings
|
55 |
+
embeddings = transformer([source_text], st.session_state.inputs)
|
56 |
|
57 |
# 显示生成的文本
|
58 |
st.write(embeddings)
|
59 |
#output_text.success(generated_text)
|
60 |
|
61 |
+
with st.container():
|
62 |
+
for sent, cos in embeddings:
|
63 |
+
st.
|
64 |
+
|
65 |
if button_clear:
|
66 |
st.session_state.inputs.clear()
|
67 |
del st.session_state["inputs"]
|
|
|
69 |
source_text = ''
|
70 |
st.experimental_rerun()
|
71 |
|
72 |
+
|
73 |
+
|
74 |
if __name__ == "__main__":
|
75 |
# 运行应用程序
|
76 |
app()
|