Update app.py
Browse files
app.py
CHANGED
|
@@ -567,7 +567,7 @@ def clean_text(text):
|
|
| 567 |
return re.sub(r'[^آ-ی۰-۹0-9،.؟!؛+\-* ]+', '', text)
|
| 568 |
|
| 569 |
# تابعی برای پیدا کردن نزدیکترین خطوط به سوال
|
| 570 |
-
def find_closest_lines(query, doc_texts, stop_words, top_n=10
|
| 571 |
# حذف کلمات اضافی از سوال
|
| 572 |
cleaned_query = remove_stop_words(query, stop_words)
|
| 573 |
query_words = cleaned_query.split()
|
|
@@ -587,16 +587,12 @@ def find_closest_lines(query, doc_texts, stop_words, top_n=10, exclude_line=None
|
|
| 587 |
# انتخاب ۱۰ خط نزدیکتر
|
| 588 |
closest_lines = [line for line, _ in all_matched_lines[:top_n]]
|
| 589 |
|
| 590 |
-
# حذف خط خاص از لیست در صورت وجود
|
| 591 |
-
if exclude_line and exclude_line in closest_lines:
|
| 592 |
-
closest_lines.remove(exclude_line)
|
| 593 |
-
|
| 594 |
return closest_lines
|
| 595 |
|
| 596 |
# حالا این رو در کد اصلی استفاده میکنیم:
|
| 597 |
if query:
|
| 598 |
-
# پیدا کردن ۱۰ خط نزدیکتر به سوال
|
| 599 |
-
closest_lines = find_closest_lines(query, doc_texts, stop_words, top_n=10
|
| 600 |
|
| 601 |
if closest_lines:
|
| 602 |
prompt = f"""
|
|
@@ -617,5 +613,4 @@ if query:
|
|
| 617 |
st.markdown(f'<div class="chat-message">{rewritten}</div>', unsafe_allow_html=True)
|
| 618 |
|
| 619 |
else:
|
| 620 |
-
st.warning("هیچ خط مرتبطی پیدا نشد.")
|
| 621 |
-
|
|
|
|
| 567 |
return re.sub(r'[^آ-ی۰-۹0-9،.؟!؛+\-* ]+', '', text)
|
| 568 |
|
| 569 |
# تابعی برای پیدا کردن نزدیکترین خطوط به سوال
|
| 570 |
+
def find_closest_lines(query, doc_texts, stop_words, top_n=10):
|
| 571 |
# حذف کلمات اضافی از سوال
|
| 572 |
cleaned_query = remove_stop_words(query, stop_words)
|
| 573 |
query_words = cleaned_query.split()
|
|
|
|
| 587 |
# انتخاب ۱۰ خط نزدیکتر
|
| 588 |
closest_lines = [line for line, _ in all_matched_lines[:top_n]]
|
| 589 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
return closest_lines
|
| 591 |
|
| 592 |
# حالا این رو در کد اصلی استفاده میکنیم:
|
| 593 |
if query:
|
| 594 |
+
# پیدا کردن ۱۰ خط نزدیکتر به سوال
|
| 595 |
+
closest_lines = find_closest_lines(query, doc_texts, stop_words, top_n=10)
|
| 596 |
|
| 597 |
if closest_lines:
|
| 598 |
prompt = f"""
|
|
|
|
| 613 |
st.markdown(f'<div class="chat-message">{rewritten}</div>', unsafe_allow_html=True)
|
| 614 |
|
| 615 |
else:
|
| 616 |
+
st.warning("هیچ خط مرتبطی پیدا نشد.")
|
|
|