Update app.py
Browse files
app.py
CHANGED
@@ -539,6 +539,17 @@ def load_and_process_documents(path):
|
|
539 |
|
540 |
doc_texts = load_and_process_documents(folder_path)
|
541 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
542 |
# تابعی برای استخراج کلمات از متن
|
543 |
def extract_keywords_from_text(text, query_words):
|
544 |
matched_lines = []
|
@@ -555,9 +566,10 @@ def clean_text(text):
|
|
555 |
return re.sub(r'[^آ-ی۰-۹0-9،.؟!؛+\-* ]+', '', text)
|
556 |
|
557 |
# تابعی برای پیدا کردن نزدیکترین خطوط به سوال
|
558 |
-
def find_closest_lines(query, doc_texts, top_n=20, exclude_line=None):
|
559 |
-
#
|
560 |
-
|
|
|
561 |
|
562 |
all_matched_lines = []
|
563 |
|
@@ -583,7 +595,7 @@ def find_closest_lines(query, doc_texts, top_n=20, exclude_line=None):
|
|
583 |
# حالا این رو در کد اصلی استفاده میکنیم:
|
584 |
if query:
|
585 |
# پیدا کردن ۲۰ خط نزدیکتر به سوال (و حذف یک خط خاص)
|
586 |
-
closest_lines = find_closest_lines(query, doc_texts, top_n=20, exclude_line=None)
|
587 |
|
588 |
if closest_lines:
|
589 |
prompt = f"""
|
|
|
539 |
|
540 |
doc_texts = load_and_process_documents(folder_path)
|
541 |
|
542 |
+
stop_words = [
|
543 |
+
"است", "و", "با", "که", "در", "از", "برای", "به", "بر", "تا", "این", "آن", "یک", "کدام", "کجا", "هم", "همه",
|
544 |
+
"یا", "از", "بر", "همچنین", "می", "باید", "شود", "شد", "گفت", "گویا", "داشت", "داشتن", "کنند", "کنیم",
|
545 |
+
"کرد", "کردن", "نیز", "یا", "اگر", "ای", "اینکه", "نه", "باشید", "باشم", "باشی", "در حالی که", "مگر", "چرا"
|
546 |
+
]
|
547 |
+
|
548 |
+
# تابعی برای پاکسازی کلمات اضافی از سوال
|
549 |
+
def remove_stop_words(text, stop_words):
|
550 |
+
words = text.split()
|
551 |
+
return " ".join([word for word in words if word not in stop_words])
|
552 |
+
|
553 |
# تابعی برای استخراج کلمات از متن
|
554 |
def extract_keywords_from_text(text, query_words):
|
555 |
matched_lines = []
|
|
|
566 |
return re.sub(r'[^آ-ی۰-۹0-9،.؟!؛+\-* ]+', '', text)
|
567 |
|
568 |
# تابعی برای پیدا کردن نزدیکترین خطوط به سوال
|
569 |
+
def find_closest_lines(query, doc_texts, stop_words, top_n=20, exclude_line=None):
|
570 |
+
# حذف کلمات اضافی از سوال
|
571 |
+
cleaned_query = remove_stop_words(query, stop_words)
|
572 |
+
query_words = cleaned_query.split()
|
573 |
|
574 |
all_matched_lines = []
|
575 |
|
|
|
595 |
# حالا این رو در کد اصلی استفاده میکنیم:
|
596 |
if query:
|
597 |
# پیدا کردن ۲۰ خط نزدیکتر به سوال (و حذف یک خط خاص)
|
598 |
+
closest_lines = find_closest_lines(query, doc_texts, stop_words, top_n=20, exclude_line=None)
|
599 |
|
600 |
if closest_lines:
|
601 |
prompt = f"""
|