M17idd commited on
Commit
78dcb52
·
1 Parent(s): c784784

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -20
app.py CHANGED
@@ -539,29 +539,19 @@ st.markdown("""
539
 
540
 
541
 
542
- from sentence_transformers import SentenceTransformer, util
543
-
544
- model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')
545
-
546
  if query:
547
- threshold = 0.50
548
- found = False
549
-
550
- # محاسبه بردارهای جملات و سوال
551
- sentence_embeddings = model.encode(all_sentences, convert_to_tensor=True)
552
- query_embedding = model.encode(query, convert_to_tensor=True)
553
-
554
- # محاسبه شباهت‌ها
555
- similarities = util.cos_sim(query_embedding, sentence_embeddings)[0]
556
 
557
- # استخراج اندیس‌هایی که شباهتشان از آستانه بیشتر است
558
- top_indices = [i for i, sim in enumerate(similarities) if sim >= threshold]
 
 
559
 
560
- if top_indices:
 
561
  found = True
562
- # ترکیب همه جملات مشابه در یک متن واحد
563
- matched_sentences = "\n".join([all_sentences[i] for i in top_indices])
564
- st.markdown(matched_sentences)
565
 
566
  # ساخت پرامپت اصلی برای تولید پاسخ نهایی حرفه‌ای
567
  prompt = f"""
@@ -571,7 +561,7 @@ if query:
571
  {query}
572
 
573
  پاسخ‌ها:
574
- {matched_sentences}
575
 
576
  پاسخ نهایی حرفه‌ای بازنویسی‌شده:
577
  """
 
539
 
540
 
541
 
 
 
 
 
542
  if query:
543
+ threshold = 70 # چون fuzz خروجی بین 0 تا 100 می‌ده
544
+ matched_sentences = []
 
 
 
 
 
 
 
545
 
546
+ for idx, sentence in enumerate(all_sentences):
547
+ similarity = fuzz.partial_ratio(query, sentence)
548
+ if similarity >= threshold:
549
+ matched_sentences.append(sentence)
550
 
551
+ if matched_sentences:
552
+ matched_text = "\n".join(matched_sentences)
553
  found = True
554
+ st.markdown(matched_text)
 
 
555
 
556
  # ساخت پرامپت اصلی برای تولید پاسخ نهایی حرفه‌ای
557
  prompt = f"""
 
561
  {query}
562
 
563
  پاسخ‌ها:
564
+ {matched_text}
565
 
566
  پاسخ نهایی حرفه‌ای بازنویسی‌شده:
567
  """