Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -28,9 +28,9 @@ def question_answering(question):
|
|
28 |
print(question)
|
29 |
query_sentence = [question]
|
30 |
query_embedding = st.session_state.model_embedding.encode(query_sentence)
|
31 |
-
k =
|
32 |
D, I = index_loaded.search(query_embedding.astype('float32'), k) # D is distances, I is indices
|
33 |
-
answer = [question_answerer(question=query_sentence[0], context=articles[I[0][i]], max_answer_len =
|
34 |
best_answer = max(answer, key=lambda x: x['score'])
|
35 |
print(best_answer['answer'])
|
36 |
if best_answer['score'] > 0.5:
|
@@ -47,7 +47,7 @@ for message in st.session_state.messages:
|
|
47 |
|
48 |
def clean_answer(s):
|
49 |
# Sử dụng regex để loại bỏ tất cả các ký tự đặc biệt ở cuối chuỗi
|
50 |
-
return re.sub(r'[^
|
51 |
|
52 |
if prompt := st.chat_input("What is up?"):
|
53 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
|
|
28 |
print(question)
|
29 |
query_sentence = [question]
|
30 |
query_embedding = st.session_state.model_embedding.encode(query_sentence)
|
31 |
+
k = 20
|
32 |
D, I = index_loaded.search(query_embedding.astype('float32'), k) # D is distances, I is indices
|
33 |
+
answer = [question_answerer(question=query_sentence[0], context=articles[I[0][i]], max_answer_len = 256) for i in range(k)]
|
34 |
best_answer = max(answer, key=lambda x: x['score'])
|
35 |
print(best_answer['answer'])
|
36 |
if best_answer['score'] > 0.5:
|
|
|
47 |
|
48 |
def clean_answer(s):
|
49 |
# Sử dụng regex để loại bỏ tất cả các ký tự đặc biệt ở cuối chuỗi
|
50 |
+
return re.sub(r'[^aAàÀảẢáÁạẠăĂằẰẳẲẵẴắẮặẶâÂầẦẩẨẫẪấẤậẬbBcCdDđĐeEèÈẻẺẽẼéÉẹẸêÊềỀểỂễỄếẾệỆfFgGhHiIìÌỉỈĩĨíÍịỊjJkKlLmMnNoOòÒỏỎõÕóÓọỌôÔồỒổỔỗỖốỐộỘơƠờỜởỞỡỠớỚợỢpPqQrRsStTuUùÙủỦũŨúÚụỤưƯừỪửỬữỮứỨựỰvVwWxXyYỳỲỷỶỹỸýÝỵỴzZ0-9]+$', '', s)
|
51 |
|
52 |
if prompt := st.chat_input("What is up?"):
|
53 |
st.session_state.messages.append({"role": "user", "content": prompt})
|