Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1873,38 +1873,51 @@ def generate_sms_with_timer(model_prompt: str, product_name: str, key_message: s
|
|
1873 |
start = time.time()
|
1874 |
best_sms = None
|
1875 |
best_non_crit_count = math.inf # сколько некритич. проверок не пройдено (минимизируем)
|
1876 |
-
|
1877 |
-
while True:
|
1878 |
|
|
|
|
|
|
|
1879 |
now = time.time()
|
1880 |
-
|
1881 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1882 |
break
|
1883 |
-
|
|
|
1884 |
sms, crit_ok, failed_non_crit = attempt_generate_sms_with_checks(model_prompt, product_name, key_message)
|
|
|
1885 |
|
1886 |
if crit_ok:
|
1887 |
-
#
|
1888 |
non_crit_count = len(failed_non_crit)
|
1889 |
if non_crit_count == 0:
|
1890 |
-
#
|
1891 |
-
|
1892 |
-
|
|
|
1893 |
if non_crit_count < best_non_crit_count:
|
1894 |
best_non_crit_count = non_crit_count
|
1895 |
best_sms = sms
|
1896 |
-
|
1897 |
-
# crit fail => пропускаем
|
1898 |
-
pass
|
1899 |
|
1900 |
-
|
|
|
|
|
|
|
|
|
1901 |
if best_sms is not None:
|
1902 |
-
|
1903 |
return best_sms
|
1904 |
else:
|
1905 |
-
|
1906 |
return "Не удалось за 1,5 минуты создать SMS, прошедшее все критические проверки."
|
1907 |
|
|
|
1908 |
def cut_message(message: str):
|
1909 |
if '------' in message:
|
1910 |
message = message.split('------')[0].strip()
|
|
|
1873 |
start = time.time()
|
1874 |
best_sms = None
|
1875 |
best_non_crit_count = math.inf # сколько некритич. проверок не пройдено (минимизируем)
|
|
|
|
|
1876 |
|
1877 |
+
i = 0 # Счётчик итераций
|
1878 |
+
while True:
|
1879 |
+
i += 1
|
1880 |
now = time.time()
|
1881 |
+
elapsed = now - start
|
1882 |
+
|
1883 |
+
# Печатаем отладку по каждой итерации
|
1884 |
+
print(f"[DEBUG] iteration={i}, elapsed={elapsed:.1f} s")
|
1885 |
+
|
1886 |
+
# Проверяем, не вышли ли за предел 90 секунд
|
1887 |
+
if elapsed > max_time_sec:
|
1888 |
+
print(f"[DEBUG] таймер вышел: elapsed={elapsed:.1f} s => break")
|
1889 |
break
|
1890 |
+
|
1891 |
+
# Генерируем SMS и проверяем
|
1892 |
sms, crit_ok, failed_non_crit = attempt_generate_sms_with_checks(model_prompt, product_name, key_message)
|
1893 |
+
print(f"[DEBUG] iteration={i}, crit_ok={crit_ok}, failed_non_crit={failed_non_crit}")
|
1894 |
|
1895 |
if crit_ok:
|
1896 |
+
# SMS прошло критические проверки
|
1897 |
non_crit_count = len(failed_non_crit)
|
1898 |
if non_crit_count == 0:
|
1899 |
+
# Идеальное SMS => сразу return
|
1900 |
+
print(f"[DEBUG] iteration={i} => нашли SMS без некритических ошибок, возвращаем сразу.")
|
1901 |
+
return sms
|
1902 |
+
|
1903 |
if non_crit_count < best_non_crit_count:
|
1904 |
best_non_crit_count = non_crit_count
|
1905 |
best_sms = sms
|
1906 |
+
print(f"[DEBUG] iteration={i} => новое лучшее SMS, некритических={best_non_crit_count}")
|
|
|
|
|
1907 |
|
1908 |
+
# Если crit_fail, идём на следующую итерацию, без обновлений best_sms
|
1909 |
+
|
1910 |
+
# (опционально) time.sleep(1) — чтобы не «спамить» модель слишком часто
|
1911 |
+
|
1912 |
+
# Если дошли сюда, значит время вышло (или цикл прерван вручную где-то)
|
1913 |
if best_sms is not None:
|
1914 |
+
print(f"[DEBUG] время истекло, возвращаем best_sms c {best_non_crit_count} некрит. ошибками")
|
1915 |
return best_sms
|
1916 |
else:
|
1917 |
+
print("[DEBUG] ни одно SMS не прошло критические проверки => возвращаем фейл")
|
1918 |
return "Не удалось за 1,5 минуты создать SMS, прошедшее все критические проверки."
|
1919 |
|
1920 |
+
|
1921 |
def cut_message(message: str):
|
1922 |
if '------' in message:
|
1923 |
message = message.split('------')[0].strip()
|