Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files
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 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
554 |
|
555 |
def add_human_touch(text):
|
556 |
-
"""إضافة لمسة
|
557 |
# إضافة تعبيرات شخصية
|
558 |
personal_expressions = [
|
559 |
-
"
|
560 |
-
"
|
561 |
-
"
|
562 |
-
"
|
563 |
-
"
|
564 |
]
|
565 |
|
566 |
-
# إضافة
|
567 |
-
|
568 |
-
"
|
569 |
-
"
|
570 |
-
"
|
571 |
-
"
|
572 |
-
"
|
573 |
]
|
574 |
|
575 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
576 |
enhanced_paragraphs = []
|
577 |
|
578 |
for i, paragraph in enumerate(paragraphs):
|
579 |
-
if
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|