Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -136,37 +136,37 @@ def generate_message_gigachat_plus(prompt, temperature=0.87):
|
|
136 |
except Exception as e:
|
137 |
return f"Ошибка при обращении к GigaChat-Plus: {e}"
|
138 |
|
139 |
-
def generate_message_gpt4o_with_retry(prompt
|
140 |
for _ in range(10): # Максимум 10 попыток
|
141 |
-
message = generate_message_gpt4o(prompt
|
142 |
if len(message) <= 250:
|
143 |
return message
|
144 |
return message # Возвращаем последнее сгенерированное сообщение, если все попытки не удались
|
145 |
|
146 |
-
def generate_message_gigachat_pro_with_retry(prompt
|
147 |
for _ in range(10):
|
148 |
-
message = generate_message_gigachat_pro(prompt
|
149 |
if len(message) <= 250:
|
150 |
return message
|
151 |
return message
|
152 |
|
153 |
-
def generate_message_gigachat_lite_with_retry(prompt
|
154 |
for _ in range(10):
|
155 |
-
message = generate_message_gigachat_lite(prompt
|
156 |
if len(message) <= 250:
|
157 |
return message
|
158 |
return message
|
159 |
|
160 |
-
def generate_message_gigachat_plus_with_retry(prompt
|
161 |
for _ in range(10):
|
162 |
-
message = generate_message_gigachat_plus(prompt
|
163 |
if len(message) <= 250:
|
164 |
return message
|
165 |
return message
|
166 |
|
167 |
|
168 |
# Обновляем генерацию сообщений для отображения в интерфейсе
|
169 |
-
def generate_messages(description, advantages, *selected_values
|
170 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
171 |
|
172 |
results = {
|
@@ -177,33 +177,36 @@ def generate_messages(description, advantages, *selected_values, gpt4o_temperatu
|
|
177 |
"gigachat_plus": None
|
178 |
}
|
179 |
|
180 |
-
|
181 |
-
|
|
|
182 |
gpt4o_length = len(results["gpt4o"])
|
183 |
gpt4o_display = f"{results['gpt4o']}\n\n------\nКоличество знаков: {gpt4o_length}"
|
|
|
184 |
|
185 |
-
|
186 |
-
results["gigachat_pro"] = generate_message_gigachat_pro_with_retry(standard_prompt, temperature=gigachat_pro_temperature)
|
187 |
gigachat_pro_length = len(results["gigachat_pro"])
|
188 |
gigachat_pro_display = f"{results['gigachat_pro']}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
|
|
189 |
|
190 |
time.sleep(2)
|
191 |
|
192 |
-
|
193 |
-
results["gigachat_lite"] = generate_message_gigachat_lite_with_retry(standard_prompt, temperature=gigachat_lite_temperature)
|
194 |
gigachat_lite_length = len(results["gigachat_lite"])
|
195 |
gigachat_lite_display = f"{results['gigachat_lite']}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
|
|
196 |
|
197 |
time.sleep(2)
|
198 |
|
199 |
-
|
200 |
-
results["gigachat_plus"] = generate_message_gigachat_plus_with_retry(standard_prompt, temperature=gigachat_plus_temperature)
|
201 |
gigachat_plus_length = len(results["gigachat_plus"])
|
202 |
gigachat_plus_display = f"{results['gigachat_plus']}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
|
|
203 |
|
204 |
return results
|
205 |
|
206 |
|
|
|
207 |
# Функция для генерации персонализиров��нного промпта
|
208 |
def generate_personalization_prompt(*selected_values):
|
209 |
prompt = "Адаптируй, не превышая длину сообщения в 250 знаков с пробелами, текст с учетом следующих особенностей:\n"
|
|
|
136 |
except Exception as e:
|
137 |
return f"Ошибка при обращении к GigaChat-Plus: {e}"
|
138 |
|
139 |
+
def generate_message_gpt4o_with_retry(prompt):
|
140 |
for _ in range(10): # Максимум 10 попыток
|
141 |
+
message = generate_message_gpt4o(prompt)
|
142 |
if len(message) <= 250:
|
143 |
return message
|
144 |
return message # Возвращаем последнее сгенерированное сообщение, если все попытки не удались
|
145 |
|
146 |
+
def generate_message_gigachat_pro_with_retry(prompt):
|
147 |
for _ in range(10):
|
148 |
+
message = generate_message_gigachat_pro(prompt)
|
149 |
if len(message) <= 250:
|
150 |
return message
|
151 |
return message
|
152 |
|
153 |
+
def generate_message_gigachat_lite_with_retry(prompt):
|
154 |
for _ in range(10):
|
155 |
+
message = generate_message_gigachat_lite(prompt)
|
156 |
if len(message) <= 250:
|
157 |
return message
|
158 |
return message
|
159 |
|
160 |
+
def generate_message_gigachat_plus_with_retry(prompt):
|
161 |
for _ in range(10):
|
162 |
+
message = generate_message_gigachat_plus(prompt)
|
163 |
if len(message) <= 250:
|
164 |
return message
|
165 |
return message
|
166 |
|
167 |
|
168 |
# Обновляем генерацию сообщений для отображения в интерфейсе
|
169 |
+
def generate_messages(description, advantages, *selected_values):
|
170 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
171 |
|
172 |
results = {
|
|
|
177 |
"gigachat_plus": None
|
178 |
}
|
179 |
|
180 |
+
yield results["prompt"], "", "", "", "", "Генерация стандартного промпта завершена"
|
181 |
+
|
182 |
+
results["gpt4o"] = generate_message_gpt4o_with_retry(standard_prompt)
|
183 |
gpt4o_length = len(results["gpt4o"])
|
184 |
gpt4o_display = f"{results['gpt4o']}\n\n------\nКоличество знаков: {gpt4o_length}"
|
185 |
+
yield results["prompt"], gpt4o_display, "", "", "", "Сообщение GPT-4o сгенерировано"
|
186 |
|
187 |
+
results["gigachat_pro"] = generate_message_gigachat_pro_with_retry(standard_prompt)
|
|
|
188 |
gigachat_pro_length = len(results["gigachat_pro"])
|
189 |
gigachat_pro_display = f"{results['gigachat_pro']}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
190 |
+
yield results["prompt"], gpt4o_display, gigachat_pro_display, "", "", "Сообщение GigaChat-Pro сгенерировано"
|
191 |
|
192 |
time.sleep(2)
|
193 |
|
194 |
+
results["gigachat_lite"] = generate_message_gigachat_lite_with_retry(standard_prompt)
|
|
|
195 |
gigachat_lite_length = len(results["gigachat_lite"])
|
196 |
gigachat_lite_display = f"{results['gigachat_lite']}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
197 |
+
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, "", "Сообщение GigaChat-Lite сгенерировано"
|
198 |
|
199 |
time.sleep(2)
|
200 |
|
201 |
+
results["gigachat_plus"] = generate_message_gigachat_plus_with_retry(standard_prompt)
|
|
|
202 |
gigachat_plus_length = len(results["gigachat_plus"])
|
203 |
gigachat_plus_display = f"{results['gigachat_plus']}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
204 |
+
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, "Все сообщения сгенерированы"
|
205 |
|
206 |
return results
|
207 |
|
208 |
|
209 |
+
|
210 |
# Функция для генерации персонализиров��нного промпта
|
211 |
def generate_personalization_prompt(*selected_values):
|
212 |
prompt = "Адаптируй, не превышая длину сообщения в 250 знаков с пробелами, текст с учетом следующих особенностей:\n"
|