fruitpicker01 commited on
Commit
f8d1f68
·
verified ·
1 Parent(s): 8b77c1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -14
app.py CHANGED
@@ -515,21 +515,23 @@ def correct_dash_usage(text):
515
  # Join the sentences back
516
  text = ' '.join(sentences)
517
 
518
- # Step 9: Replace common abbreviations and acronyms (Ип -> ИП, Ооо -> ООО, Рф -> РФ)
519
- text = re.sub(r'\bИп\b', 'ИП', text, flags=re.IGNORECASE)
520
- text = re.sub(r'\bОоо\b', 'ООО', text, flags=re.IGNORECASE)
521
- text = re.sub(r'\bРф\b', 'РФ', text, flags=re.IGNORECASE)
522
-
523
- # Step 10: Replace specific words (пользуйтесь -> пользуйтесь, ею -> ей)
524
- text = re.sub(r'\bпользовуйтесь\b', 'пользуйтесь', text, flags=re.IGNORECASE)
525
- text = re.sub(r'\bею\b', 'ей', text, flags=re.IGNORECASE)
526
-
527
  def restore_yo(text):
528
  morph = pymorphy3.MorphAnalyzer()
529
  words = text.split()
530
  restored_words = []
531
 
532
  for word in words:
 
 
 
 
 
 
 
 
 
 
 
533
  parsed = morph.parse(word)[0]
534
  restored_word = parsed.word
535
 
@@ -543,6 +545,58 @@ def correct_dash_usage(text):
543
 
544
  text = restore_yo(text)
545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
  return text
547
 
548
 
@@ -1568,11 +1622,11 @@ def personalize_and_save(
1568
 
1569
  # После завершения персонализации, сохраняем результаты
1570
  if last_personalization_result:
1571
- checks_gigachat_pro = perform_checks(last_personalization_result[1])
1572
- checks_gigachat_lite = perform_checks(last_personalization_result[2])
1573
- checks_gigachat_plus = perform_checks(last_personalization_result[3])
1574
- checks_gpt4o = perform_checks(last_personalization_result[4])
1575
- checks_meta_llama_405b = perform_checks(last_personalization_result[5])
1576
 
1577
  # Форматирование результатов проверок
1578
  formatted_checks = [
 
515
  # Join the sentences back
516
  text = ' '.join(sentences)
517
 
 
 
 
 
 
 
 
 
 
518
  def restore_yo(text):
519
  morph = pymorphy3.MorphAnalyzer()
520
  words = text.split()
521
  restored_words = []
522
 
523
  for word in words:
524
+ # Пропускать обработку, если слово полностью в верхнем регистре (аббревиатуры)
525
+ if word.isupper():
526
+ restored_words.append(word)
527
+ continue
528
+
529
+ # Пропускать обработку, если слово "все" (независимо от регистра)
530
+ if word.lower() == "все":
531
+ restored_words.append(word)
532
+ continue
533
+
534
+ # Обработка остальных слов
535
  parsed = morph.parse(word)[0]
536
  restored_word = parsed.word
537
 
 
545
 
546
  text = restore_yo(text)
547
 
548
+ # Step 9: Replace common abbreviations and acronyms (Ип -> ИП, Ооо -> ООО, Рф -> РФ)
549
+ text = re.sub(r'\bИп\b', 'ИП', text, flags=re.IGNORECASE)
550
+ text = re.sub(r'\bОоо\b', 'ООО', text, flags=re.IGNORECASE)
551
+ text = re.sub(r'\bРф\b', 'РФ', text, flags=re.IGNORECASE)
552
+
553
+ # Step 10: Replace specific words (пользуйтесь -> пользуйтесь, ею -> ей)
554
+ text = re.sub(r'\bпользовуйтесь\b', 'пользуйтесь', text, flags=re.IGNORECASE)
555
+ text = re.sub(r'\bею\b', 'ей', text, flags=re.IGNORECASE)
556
+ text = re.sub(r'\bповышьте\b', 'повысьте', text, flags=re.IGNORECASE)
557
+
558
+ text = re.sub(r'\bСбербизнес\b', 'СберБизнес', text, flags=re.IGNORECASE)
559
+ text = re.sub(r'\bСбербизнеса\b', 'СберБизнес', text, flags=re.IGNORECASE)
560
+ text = re.sub(r'\bСбербизнесе\b', 'СберБизнес', text, flags=re.IGNORECASE)
561
+ text = re.sub(r'\bСбербанк\b', 'СберБанк', text, flags=re.IGNORECASE)
562
+ text = re.sub(r'\bвашего ООО\b', 'вашей компании', text, flags=re.IGNORECASE)
563
+ text = re.sub(r'\b0₽\b', '0 р', text, flags=re.IGNORECASE)
564
+ text = re.sub(r'\b₽\b', 'р', text, flags=re.IGNORECASE)
565
+
566
+ # Step 11: Replace all forms of "рублей", "рубля", "руб." with "р"
567
+ # Используем два отдельных регулярных выражения для точности
568
+ # 1. Заменяем "руб." на "р", учитывая, что "руб." может быть перед символом "/" или другим несловесным символом
569
+ text = re.sub(r'\bруб\.(?=\W|$)', 'р', text, flags=re.IGNORECASE)
570
+ # 2. Заменяем "рубля" и "рублей" на "р"
571
+ text = re.sub(r'\bруб(?:ля|лей)\b', 'р', text, flags=re.IGNORECASE)
572
+
573
+ # Step 12: Replace thousands and millions with appropriate abbreviations
574
+ text = re.sub(r'(\d+)\s+тысяч(?:а|и)?(?:\s+рублей)?', r'\1 000 р', text, flags=re.IGNORECASE)
575
+ text = re.sub(r'(\d+)\s*тыс\.\s*руб\.', r'\1 000 р', text, flags=re.IGNORECASE)
576
+ text = re.sub(r'(\d+)\s*тыс\.\s*р\.', r'\1 000 р', text, flags=re.IGNORECASE)
577
+ text = re.sub(r'(\d+)\s*тыс\.\s*р', r'\1 000 р', text, flags=re.IGNORECASE)
578
+
579
+ # Replace millions with "млн"
580
+ text = re.sub(r'(\d+)\s+миллиона\b|\bмиллионов\b', r'\1 млн', text, flags=re.IGNORECASE)
581
+ text = re.sub(r'(\d+)\s*млн\s*руб\.', r'\1 млн р', text, flags=re.IGNORECASE)
582
+
583
+ # Ensure space formatting around currency abbreviations
584
+ text = re.sub(r'(\d+)\s*р\b', r'\1 р', text)
585
+
586
+ # Step 13: Remove sentences containing "никаких посещений" or "никаких визитов"
587
+ def remove_specific_sentences(text):
588
+ sentences = re.split(r'(?<=[.!?])\s+', text) # Разбиваем текст на предложения
589
+ filtered_sentences = [
590
+ sentence for sentence in sentences
591
+ if not re.search(r'\bникаких\s+(посещений|визитов)\b', sentence, flags=re.IGNORECASE)
592
+ ]
593
+ return ' '.join(filtered_sentences)
594
+
595
+ # Шаг 14: Замена чисел вида "5 000 000 р" на "5 млн р"
596
+ text = re.sub(r'\b(\d+)\s+000\s+000\s*р\b', r'\1 млн р', text, flags=re.IGNORECASE)
597
+
598
+ text = remove_specific_sentences(text)
599
+
600
  return text
601
 
602
 
 
1622
 
1623
  # После завершения персонализации, сохраняем результаты
1624
  if last_personalization_result:
1625
+ checks_gigachat_pro = perform_checks(last_personalization_result[1], description, key_message)
1626
+ checks_gigachat_lite = perform_checks(last_personalization_result[2], description, key_message)
1627
+ checks_gigachat_plus = perform_checks(last_personalization_result[3], description, key_message)
1628
+ checks_gpt4o = perform_checks(last_personalization_result[4], description, key_message)
1629
+ checks_meta_llama_405b = perform_checks(last_personalization_result[5], description, key_message)
1630
 
1631
  # Форматирование результатов проверок
1632
  formatted_checks = [