thomson99 commited on
Commit
ba17bb4
·
verified ·
1 Parent(s): 9ea25c3

Upload 4 files

Browse files
Files changed (1) hide show
  1. app.py +94 -30
app.py CHANGED
@@ -542,47 +542,98 @@ def get_synonyms(word):
542
  return synonyms.get(word, [word])
543
 
544
  def enhance_text_variation(text):
545
- """تحسين تنوع النص باستخدام المرادفات"""
546
- words = text.split()
547
- enhanced_words = []
548
- for word in words:
549
- if word in get_synonyms(word) and random.random() > 0.7: # 30% فرصة للتغيير
550
- enhanced_words.append(random.choice(get_synonyms(word)))
551
- else:
552
- enhanced_words.append(word)
553
- return " ".join(enhanced_words)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
 
555
  def add_human_touch(text):
556
- """إضافة لمسة بشرية للنص"""
557
  # إضافة تعبيرات شخصية
558
  personal_expressions = [
559
- "ومن وجهة نظري",
560
- "وكما نلاحظ في واقعنا",
561
- "ومن خلال تجربتي",
562
- "وكما يتضح لنا",
563
- "ومن الملفت للنظر"
564
  ]
565
 
566
- # إضافة أمثلة واقعية
567
- real_examples = [
568
- "فعلى سبيل المثال",
569
- "ولنأخذ مثالاً على ذلك",
570
- "وخير مثال على ذلك",
571
- "ومن الأمثلة الواقعية",
572
- "وكما نرى في حياتنا اليومية"
573
  ]
574
 
575
- paragraphs = text.split("\n\n")
 
 
 
 
 
 
 
 
 
 
576
  enhanced_paragraphs = []
577
 
578
  for i, paragraph in enumerate(paragraphs):
579
- if random.random() > 0.7: # 30% فرصة لإضافة تعبير شخصي
580
- paragraph = random.choice(personal_expressions) + " + paragraph
581
- if random.random() > 0.7: # 30% فرصة لإضافة مثال
582
- paragraph += " " + random.choice(real_examples) + "."
583
- enhanced_paragraphs.append(paragraph)
584
-
585
- return "\n\n".join(enhanced_paragraphs)
 
 
 
 
 
 
 
586
 
587
  def check_grammar_and_style(text):
588
  """تحسين القواعد والأسلوب"""
@@ -604,6 +655,19 @@ def check_grammar_and_style(text):
604
  text = text.replace(" ؛", "؛")
605
  text = text.replace(" :", ":")
606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
607
  return text
608
 
609
  def generate_additional_content(topic, style, words_needed):
 
542
  return synonyms.get(word, [word])
543
 
544
  def enhance_text_variation(text):
545
+ """تحسين تنوع النص وجعله أكثر طبيعية"""
546
+ # قائمة من الكلمات المتنوعة للربط
547
+ transitions = [
548
+ "وبالتالي",
549
+ "علاوة على ذلك",
550
+ "إضافة إلى ذلك",
551
+ "من ناحية أخرى",
552
+ "في هذا السياق",
553
+ "جدير بالذكر",
554
+ "ومن الجدير بالملاحظة",
555
+ "وفي هذا الإطار",
556
+ "ومن المهم أن نذكر",
557
+ "وفي ضوء ما سبق"
558
+ ]
559
+
560
+ # قائمة من التعبيرات الشخصية
561
+ personal_touches = [
562
+ "ومن الملفت للنظر",
563
+ "ومن المثير للاهتمام",
564
+ "ومما لا شك فيه",
565
+ "وكما نلاحظ",
566
+ "وكما يتضح لنا"
567
+ ]
568
+
569
+ paragraphs = text.split('\n\n')
570
+ enhanced_paragraphs = []
571
+
572
+ for i, paragraph in enumerate(paragraphs):
573
+ if len(paragraph.strip()) > 0:
574
+ # إضافة كلمات ربط متنوعة
575
+ if i > 0 and random.random() < 0.4: # 40% احتمالية
576
+ paragraph = f"{random.choice(transitions)}, {paragraph}"
577
+
578
+ # إضافة تعبيرات شخصية
579
+ if random.random() < 0.3: # 30% احتمالية
580
+ words = paragraph.split()
581
+ insert_pos = random.randint(0, len(words) - 1)
582
+ words.insert(insert_pos, random.choice(personal_touches))
583
+ paragraph = ' '.join(words)
584
+
585
+ enhanced_paragraphs.append(paragraph)
586
+
587
+ return '\n\n'.join(enhanced_paragraphs)
588
 
589
  def add_human_touch(text):
590
+ """إضافة لمسة إنسانية للنص"""
591
  # إضافة تعبيرات شخصية
592
  personal_expressions = [
593
+ "في رأيي الشخصي",
594
+ "من وجهة نظري",
595
+ "كما أرى",
596
+ "من خلال تجربتي",
597
+ "بناءً على ملاحظاتي"
598
  ]
599
 
600
+ # إضافة روابط عاطفية
601
+ emotional_connections = [
602
+ "من المثير للاهتمام",
603
+ "من المدهش",
604
+ "من الملفت للنظر",
605
+ "من المؤثر حقاً",
606
+ "مما يجعلنا نشعر"
607
  ]
608
 
609
+ # إضافة أمثلة من الحياة اليومية
610
+ daily_examples = [
611
+ "على سبيل المثال في حياتنا اليومية",
612
+ "كما نرى في واقعنا المعاصر",
613
+ "وهذا ما نلاحظه في محيطنا",
614
+ "كما يحدث معنا يومياً",
615
+ "وهذا ما نختبره في حياتنا"
616
+ ]
617
+
618
+ # تقسيم النص إلى فقرات
619
+ paragraphs = text.split('\n\n')
620
  enhanced_paragraphs = []
621
 
622
  for i, paragraph in enumerate(paragraphs):
623
+ if len(paragraph.strip()) > 0:
624
+ # إضافة تعبيرات إنسانية بشكل عشوائي
625
+ if random.random() < 0.3: # 30% احتمالية
626
+ paragraph = f"{random.choice(personal_expressions)}, {paragraph}"
627
+
628
+ if random.random() < 0.2: # 20% احتمالية
629
+ paragraph = f"{paragraph} {random.choice(emotional_connections)}."
630
+
631
+ if random.random() < 0.15: # 15% احتمالية
632
+ paragraph = f"{paragraph} {random.choice(daily_examples)}."
633
+
634
+ enhanced_paragraphs.append(paragraph)
635
+
636
+ return '\n\n'.join(enhanced_paragraphs)
637
 
638
  def check_grammar_and_style(text):
639
  """تحسين القواعد والأسلوب"""
 
655
  text = text.replace(" ؛", "؛")
656
  text = text.replace(" :", ":")
657
 
658
+ # تحسين المسافات
659
+ text = re.sub(r'\s+', ' ', text) # توحيد المسافات
660
+ text = re.sub(r'\s*\n\s*', '\n', text) # تنظيف المسافات حول الأسطر الجديدة
661
+
662
+ # تحسين الأسلوب
663
+ text = text.replace(" .", ".")
664
+ text = text.replace(" ،", "،")
665
+ text = text.replace("،،", "،")
666
+ text = text.replace("..", ".")
667
+
668
+ # إضافة مسافة بعد علامات الترقيم
669
+ text = re.sub(r'([.،؛؟!])\s*([^\s])', r'\1 \2', text)
670
+
671
  return text
672
 
673
  def generate_additional_content(topic, style, words_needed):