Update app.py
Browse files
app.py
CHANGED
@@ -588,18 +588,30 @@ def find_closest_lines(query, doc_texts, stop_words, top_n=10):
|
|
588 |
|
589 |
return closest_lines
|
590 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
591 |
# حالا این رو در کد اصلی استفاده میکنیم:
|
592 |
if query:
|
593 |
# پیدا کردن ۱۰ خط نزدیکتر به سوال
|
594 |
closest_lines = find_closest_lines(query, doc_texts, stop_words, top_n=3)
|
595 |
|
596 |
-
|
|
|
|
|
|
|
597 |
prompt = f"""
|
598 |
لطفاً با توجه به سؤال زیر و محتوای خطوط مرتبط، یک پاسخ نهایی حرفهای، دقیق و روان تولید کن. فقط از متن خطوط مرتبط استفاده کن. اگر اطلاعات کافی در متن وجود ندارد، صادقانه اعلام کن.
|
599 |
سوال:
|
600 |
{query}
|
601 |
خطوط مرتبط:
|
602 |
-
{
|
603 |
پاسخ نهایی:
|
604 |
"""
|
605 |
|
@@ -612,4 +624,4 @@ if query:
|
|
612 |
st.markdown(f'<div class="chat-message">{rewritten}</div>', unsafe_allow_html=True)
|
613 |
|
614 |
else:
|
615 |
-
st.warning("هیچ خط مرتبطی پیدا نشد.")
|
|
|
588 |
|
589 |
return closest_lines
|
590 |
|
591 |
+
# تابعی برای حذف کلمات توقف از یک لیست از خطوط
|
592 |
+
def remove_stop_words_from_lines(lines, stop_words):
|
593 |
+
cleaned_lines = []
|
594 |
+
for line in lines:
|
595 |
+
words = line.split()
|
596 |
+
cleaned_words = [word for word in words if word not in stop_words]
|
597 |
+
cleaned_lines.append(" ".join(cleaned_words))
|
598 |
+
return cleaned_lines
|
599 |
+
|
600 |
# حالا این رو در کد اصلی استفاده میکنیم:
|
601 |
if query:
|
602 |
# پیدا کردن ۱۰ خط نزدیکتر به سوال
|
603 |
closest_lines = find_closest_lines(query, doc_texts, stop_words, top_n=3)
|
604 |
|
605 |
+
# حذف کلمات توقف از خطوط نزدیک
|
606 |
+
cleaned_closest_lines = remove_stop_words_from_lines(closest_lines, stop_words)
|
607 |
+
|
608 |
+
if cleaned_closest_lines:
|
609 |
prompt = f"""
|
610 |
لطفاً با توجه به سؤال زیر و محتوای خطوط مرتبط، یک پاسخ نهایی حرفهای، دقیق و روان تولید کن. فقط از متن خطوط مرتبط استفاده کن. اگر اطلاعات کافی در متن وجود ندارد، صادقانه اعلام کن.
|
611 |
سوال:
|
612 |
{query}
|
613 |
خطوط مرتبط:
|
614 |
+
{cleaned_closest_lines}
|
615 |
پاسخ نهایی:
|
616 |
"""
|
617 |
|
|
|
624 |
st.markdown(f'<div class="chat-message">{rewritten}</div>', unsafe_allow_html=True)
|
625 |
|
626 |
else:
|
627 |
+
st.warning("هیچ خط مرتبطی پیدا نشد.")
|