Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -76,7 +76,7 @@ def generate_standard_prompt(description, advantages, *selected_values):
|
|
76 |
return prompt
|
77 |
|
78 |
# Функции для генерации сообщений
|
79 |
-
def generate_message_gpt4o(prompt):
|
80 |
try:
|
81 |
headers = {
|
82 |
"Content-Type": "application/json",
|
@@ -85,11 +85,12 @@ def generate_message_gpt4o(prompt):
|
|
85 |
data = {
|
86 |
"model": "chatgpt-4o-latest",
|
87 |
"messages": [{"role": "system", "content": prompt}],
|
88 |
-
"max_tokens": 101
|
|
|
89 |
}
|
90 |
response = requests.post("https://api.openai.com/v1/chat/completions", json=data, headers=headers)
|
91 |
response_data = response.json()
|
92 |
-
return response_data["choices"][0]["message"]["content"].strip()
|
93 |
except Exception as e:
|
94 |
return f"Ошибка при обращении к ChatGPT-4o-Latest: {e}"
|
95 |
|
@@ -102,29 +103,32 @@ def clean_message(message):
|
|
102 |
return message
|
103 |
|
104 |
# Обновленные функции генерации сообщений с учетом обрезки незаконченных предложений
|
105 |
-
def generate_message_gigachat_pro(prompt):
|
106 |
try:
|
107 |
messages = [SystemMessage(content=prompt)]
|
|
|
108 |
res = chat_pro(messages)
|
109 |
cleaned_message = clean_message(res.content.strip())
|
110 |
return cleaned_message
|
111 |
except Exception as e:
|
112 |
return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
113 |
|
114 |
-
def generate_message_gigachat_lite(prompt):
|
115 |
try:
|
116 |
time.sleep(2)
|
117 |
messages = [SystemMessage(content=prompt)]
|
|
|
118 |
res = chat_lite(messages)
|
119 |
cleaned_message = clean_message(res.content.strip())
|
120 |
return cleaned_message
|
121 |
except Exception as e:
|
122 |
return f"Ошибка при обращении к GigaChat-Lite: {e}"
|
123 |
|
124 |
-
def generate_message_gigachat_plus(prompt):
|
125 |
try:
|
126 |
time.sleep(2)
|
127 |
messages = [SystemMessage(content=prompt)]
|
|
|
128 |
res = chat_plus(messages)
|
129 |
cleaned_message = clean_message(res.content.strip())
|
130 |
return cleaned_message
|
@@ -159,9 +163,43 @@ def generate_message_gigachat_plus_with_retry(prompt):
|
|
159 |
return message
|
160 |
return message
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
# Обновляем генерацию сообщений для отображения в интерфейсе
|
164 |
-
def generate_messages(description, advantages, *selected_values):
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
166 |
|
167 |
results = {
|
@@ -174,34 +212,32 @@ def generate_messages(description, advantages, *selected_values):
|
|
174 |
|
175 |
yield results["prompt"], "", "", "", "", "Генерация стандартного промпта завершена"
|
176 |
|
177 |
-
results["gpt4o"] =
|
178 |
gpt4o_length = len(results["gpt4o"])
|
179 |
gpt4o_display = f"{results['gpt4o']}\n\n------\nКоличество знаков: {gpt4o_length}"
|
180 |
yield results["prompt"], gpt4o_display, "", "", "", "Сообщение GPT-4o сгенерировано"
|
181 |
|
182 |
-
results["gigachat_pro"] =
|
183 |
gigachat_pro_length = len(results["gigachat_pro"])
|
184 |
gigachat_pro_display = f"{results['gigachat_pro']}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
185 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, "", "", "Сообщение GigaChat-Pro сгенерировано"
|
186 |
|
187 |
time.sleep(2)
|
188 |
|
189 |
-
results["gigachat_lite"] =
|
190 |
gigachat_lite_length = len(results["gigachat_lite"])
|
191 |
gigachat_lite_display = f"{results['gigachat_lite']}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
192 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, "", "Сообщение GigaChat-Lite сгенерировано"
|
193 |
|
194 |
time.sleep(2)
|
195 |
|
196 |
-
results["gigachat_plus"] =
|
197 |
gigachat_plus_length = len(results["gigachat_plus"])
|
198 |
gigachat_plus_display = f"{results['gigachat_plus']}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
199 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, "Все сообщения сгенерированы"
|
200 |
|
201 |
return results
|
202 |
|
203 |
-
|
204 |
-
|
205 |
# Функция для генерации персонализированного промпта
|
206 |
def generate_personalization_prompt(*selected_values):
|
207 |
prompt = "Адаптируй, не превышая длину сообщения в 250 знаков с пробелами, текст с учетом следующих особенностей:\n"
|
@@ -246,7 +282,6 @@ def perform_personalization_gigachat_with_retry(standard_message, personalizatio
|
|
246 |
return message
|
247 |
return message
|
248 |
|
249 |
-
|
250 |
# Обновляем блок персонализации
|
251 |
def personalize_messages_with_yield(gpt4o_message, gigachat_pro_message, gigachat_lite_message, gigachat_plus_message, *selected_values):
|
252 |
personalization_prompt = generate_personalization_prompt(*selected_values)
|
@@ -272,7 +307,6 @@ def personalize_messages_with_yield(gpt4o_message, gigachat_pro_message, gigacha
|
|
272 |
gigachat_plus_display = f"{personalized_message_gigachat_plus}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
273 |
yield personalization_prompt, gpt4o_display, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, "Все персонализированные сообщения сгенерированы"
|
274 |
|
275 |
-
|
276 |
# Функция для генерации промпта проверки текста
|
277 |
def generate_error_check_prompt():
|
278 |
prompt = (
|
@@ -317,7 +351,6 @@ def generate_error_check_prompt():
|
|
317 |
)
|
318 |
return prompt
|
319 |
|
320 |
-
|
321 |
# Функция для выполнения проверки текста с использованием yield
|
322 |
def check_errors_with_yield(*personalized_messages):
|
323 |
if len(personalized_messages) < 4:
|
@@ -345,11 +378,11 @@ def check_errors_with_yield(*personalized_messages):
|
|
345 |
|
346 |
yield error_check_prompt, error_message_gpt4o, error_message_gigachat_pro, error_message_gigachat_lite, error_message_gigachat_plus, "Все результаты проверки сгенерированы"
|
347 |
|
348 |
-
|
349 |
-
def save_to_github(personalized_message, model_name, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form):
|
350 |
# Собираем все данные в один словарь
|
351 |
data_to_save = {
|
352 |
"Модель": model_name,
|
|
|
353 |
"Персонализированное сообщение": personalized_message,
|
354 |
"Комментарий": comment,
|
355 |
"Откорректированное сообщение": corrected_message,
|
@@ -384,11 +417,22 @@ def save_to_github(personalized_message, model_name, comment, corrected_message,
|
|
384 |
# Отправка POST-запроса на GitHub API для создания файла в репозитории
|
385 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
386 |
|
|
|
|
|
|
|
|
|
|
|
387 |
|
388 |
# Создание интерфейса Gradio
|
389 |
with gr.Blocks() as demo:
|
390 |
gr.Markdown("# Генерация SMS-сообщений по заданным признакам")
|
391 |
|
|
|
|
|
|
|
|
|
|
|
|
|
392 |
with gr.Row():
|
393 |
with gr.Column(scale=1):
|
394 |
description_input = gr.Textbox(
|
@@ -428,11 +472,19 @@ with gr.Blocks() as demo:
|
|
428 |
output_text_gigachat_lite = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Lite", lines=3, interactive=False)
|
429 |
output_text_gigachat_plus = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Lite+", lines=3, interactive=False)
|
430 |
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
|
437 |
with gr.Row():
|
438 |
personalize_btn = gr.Button("2. Выполнить персонализацию (нажимать только после кнопки 1)", elem_id="personalize_button")
|
@@ -464,7 +516,6 @@ with gr.Blocks() as demo:
|
|
464 |
corrected_gigachat_lite = gr.Textbox(label="", lines=3)
|
465 |
corrected_gigachat_plus = gr.Textbox(label="", lines=3)
|
466 |
|
467 |
-
|
468 |
# Отдельная строка для кнопок с использованием пустой колонки
|
469 |
with gr.Row():
|
470 |
gr.Button("Жми 👍 для сохранения удачного SMS в базу =>")
|
@@ -475,8 +526,8 @@ with gr.Blocks() as demo:
|
|
475 |
|
476 |
# Привязка кнопок к функциям сохранения
|
477 |
save_gpt4o_btn.click(
|
478 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form:
|
479 |
-
save_to_github(personalized_message, "GPT-4o", comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form),
|
480 |
inputs=[
|
481 |
personalized_output_text_gpt4o,
|
482 |
comment_gpt4o,
|
@@ -490,14 +541,15 @@ with gr.Blocks() as demo:
|
|
490 |
selections[2], # Психотип
|
491 |
selections[3], # Стадия бизнеса
|
492 |
selections[4], # Отрасль
|
493 |
-
selections[5]
|
|
|
494 |
],
|
495 |
outputs=None
|
496 |
)
|
497 |
-
|
498 |
save_gigachat_pro_btn.click(
|
499 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form:
|
500 |
-
save_to_github(personalized_message, "GigaChat-Pro", comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form),
|
501 |
inputs=[
|
502 |
personalized_output_text_gigachat_pro,
|
503 |
comment_gigachat_pro,
|
@@ -511,14 +563,15 @@ with gr.Blocks() as demo:
|
|
511 |
selections[2], # Психотип
|
512 |
selections[3], # Стадия бизнеса
|
513 |
selections[4], # Отрасль
|
514 |
-
selections[5]
|
|
|
515 |
],
|
516 |
outputs=None
|
517 |
)
|
518 |
-
|
519 |
save_gigachat_lite_btn.click(
|
520 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form:
|
521 |
-
save_to_github(personalized_message, "GigaChat-Lite", comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form),
|
522 |
inputs=[
|
523 |
personalized_output_text_gigachat_lite,
|
524 |
comment_gigachat_lite,
|
@@ -532,14 +585,15 @@ with gr.Blocks() as demo:
|
|
532 |
selections[2], # Психотип
|
533 |
selections[3], # Стадия бизнеса
|
534 |
selections[4], # Отрасль
|
535 |
-
selections[5]
|
|
|
536 |
],
|
537 |
outputs=None
|
538 |
)
|
539 |
-
|
540 |
save_gigachat_plus_btn.click(
|
541 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form:
|
542 |
-
save_to_github(personalized_message, "GigaChat-
|
543 |
inputs=[
|
544 |
personalized_output_text_gigachat_plus,
|
545 |
comment_gigachat_plus,
|
@@ -553,7 +607,8 @@ with gr.Blocks() as demo:
|
|
553 |
selections[2], # Психотип
|
554 |
selections[3], # Стадия бизнеса
|
555 |
selections[4], # Отрасль
|
556 |
-
selections[5]
|
|
|
557 |
],
|
558 |
outputs=None
|
559 |
)
|
@@ -575,5 +630,4 @@ with gr.Blocks() as demo:
|
|
575 |
]
|
576 |
)
|
577 |
|
578 |
-
|
579 |
demo.launch()
|
|
|
76 |
return prompt
|
77 |
|
78 |
# Функции для генерации сообщений
|
79 |
+
def generate_message_gpt4o(prompt, temperature=1):
|
80 |
try:
|
81 |
headers = {
|
82 |
"Content-Type": "application/json",
|
|
|
85 |
data = {
|
86 |
"model": "chatgpt-4o-latest",
|
87 |
"messages": [{"role": "system", "content": prompt}],
|
88 |
+
"max_tokens": 101,
|
89 |
+
"temperature": temperature # Передача температуры
|
90 |
}
|
91 |
response = requests.post("https://api.openai.com/v1/chat/completions", json=data, headers=headers)
|
92 |
response_data = response.json()
|
93 |
+
return clean_message(response_data["choices"][0]["message"]["content"].strip()) + f" {temperature}"
|
94 |
except Exception as e:
|
95 |
return f"Ошибка при обращении к ChatGPT-4o-Latest: {e}"
|
96 |
|
|
|
103 |
return message
|
104 |
|
105 |
# Обновленные функции генерации сообщений с учетом обрезки незаконченных предложений
|
106 |
+
def generate_message_gigachat_pro(prompt, temperature=0.87):
|
107 |
try:
|
108 |
messages = [SystemMessage(content=prompt)]
|
109 |
+
chat_pro = GigaChat(credentials=gc_key, model='GigaChat-Pro', max_tokens=68, temperature=temperature, verify_ssl_certs=False)
|
110 |
res = chat_pro(messages)
|
111 |
cleaned_message = clean_message(res.content.strip())
|
112 |
return cleaned_message
|
113 |
except Exception as e:
|
114 |
return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
115 |
|
116 |
+
def generate_message_gigachat_lite(prompt, temperature=0.87):
|
117 |
try:
|
118 |
time.sleep(2)
|
119 |
messages = [SystemMessage(content=prompt)]
|
120 |
+
chat_lite = GigaChat(credentials=gc_key, model='GigaChat', max_tokens=68, temperature=temperature, verify_ssl_certs=False)
|
121 |
res = chat_lite(messages)
|
122 |
cleaned_message = clean_message(res.content.strip())
|
123 |
return cleaned_message
|
124 |
except Exception as e:
|
125 |
return f"Ошибка при обращении к GigaChat-Lite: {e}"
|
126 |
|
127 |
+
def generate_message_gigachat_plus(prompt, temperature=0.87):
|
128 |
try:
|
129 |
time.sleep(2)
|
130 |
messages = [SystemMessage(content=prompt)]
|
131 |
+
chat_plus = GigaChat(credentials=gc_key, model='GigaChat-Plus', max_tokens=68, temperature=temperature, verify_ssl_certs=False)
|
132 |
res = chat_plus(messages)
|
133 |
cleaned_message = clean_message(res.content.strip())
|
134 |
return cleaned_message
|
|
|
163 |
return message
|
164 |
return message
|
165 |
|
166 |
+
# Создание классов для каждой модели
|
167 |
+
class GPT4oModel:
|
168 |
+
def __init__(self, temperature=1):
|
169 |
+
self.temperature = temperature
|
170 |
+
|
171 |
+
def generate_message(self, prompt):
|
172 |
+
return generate_message_gpt4o(prompt, temperature=self.temperature)
|
173 |
+
|
174 |
+
class GigaChatProModel:
|
175 |
+
def __init__(self, temperature=0.87):
|
176 |
+
self.temperature = temperature
|
177 |
+
|
178 |
+
def generate_message(self, prompt):
|
179 |
+
return generate_message_gigachat_pro(prompt, temperature=self.temperature)
|
180 |
+
|
181 |
+
class GigaChatLiteModel:
|
182 |
+
def __init__(self, temperature=0.87):
|
183 |
+
self.temperature = temperature
|
184 |
+
|
185 |
+
def generate_message(self, prompt):
|
186 |
+
return generate_message_gigachat_lite(prompt, temperature=self.temperature)
|
187 |
+
|
188 |
+
class GigaChatPlusModel:
|
189 |
+
def __init__(self, temperature=0.87):
|
190 |
+
self.temperature = temperature
|
191 |
+
|
192 |
+
def generate_message(self, prompt):
|
193 |
+
return generate_message_gigachat_plus(prompt, temperature=self.temperature)
|
194 |
|
195 |
# Обновляем генерацию сообщений для отображения в интерфейсе
|
196 |
+
def generate_messages(description, advantages, *selected_values, gpt4o_temp, gigachat_pro_temp, gigachat_lite_temp, gigachat_plus_temp):
|
197 |
+
# Создаем экземпляры классов с переданными значениями температур
|
198 |
+
gpt4o_model = GPT4oModel(temperature=gpt4o_temp)
|
199 |
+
gigachat_pro_model = GigaChatProModel(temperature=gigachat_pro_temp)
|
200 |
+
gigachat_lite_model = GigaChatLiteModel(temperature=gigachat_lite_temp)
|
201 |
+
gigachat_plus_model = GigaChatPlusModel(temperature=gigachat_plus_temp)
|
202 |
+
|
203 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
204 |
|
205 |
results = {
|
|
|
212 |
|
213 |
yield results["prompt"], "", "", "", "", "Генерация стандартного промпта завершена"
|
214 |
|
215 |
+
results["gpt4o"] = gpt4o_model.generate_message(standard_prompt)
|
216 |
gpt4o_length = len(results["gpt4o"])
|
217 |
gpt4o_display = f"{results['gpt4o']}\n\n------\nКоличество знаков: {gpt4o_length}"
|
218 |
yield results["prompt"], gpt4o_display, "", "", "", "Сообщение GPT-4o сгенерировано"
|
219 |
|
220 |
+
results["gigachat_pro"] = gigachat_pro_model.generate_message(standard_prompt)
|
221 |
gigachat_pro_length = len(results["gigachat_pro"])
|
222 |
gigachat_pro_display = f"{results['gigachat_pro']}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
223 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, "", "", "Сообщение GigaChat-Pro сгенерировано"
|
224 |
|
225 |
time.sleep(2)
|
226 |
|
227 |
+
results["gigachat_lite"] = gigachat_lite_model.generate_message(standard_prompt)
|
228 |
gigachat_lite_length = len(results["gigachat_lite"])
|
229 |
gigachat_lite_display = f"{results['gigachat_lite']}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
230 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, "", "Сообщение GigaChat-Lite сгенерировано"
|
231 |
|
232 |
time.sleep(2)
|
233 |
|
234 |
+
results["gigachat_plus"] = gigachat_plus_model.generate_message(standard_prompt)
|
235 |
gigachat_plus_length = len(results["gigachat_plus"])
|
236 |
gigachat_plus_display = f"{results['gigachat_plus']}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
237 |
yield results["prompt"], gpt4o_display, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, "Все сообщения сгенерированы"
|
238 |
|
239 |
return results
|
240 |
|
|
|
|
|
241 |
# Функция для генерации персонализированного промпта
|
242 |
def generate_personalization_prompt(*selected_values):
|
243 |
prompt = "Адаптируй, не превышая длину сообщения в 250 знаков с пробелами, текст с учетом следующих особенностей:\n"
|
|
|
282 |
return message
|
283 |
return message
|
284 |
|
|
|
285 |
# Обновляем блок персонализации
|
286 |
def personalize_messages_with_yield(gpt4o_message, gigachat_pro_message, gigachat_lite_message, gigachat_plus_message, *selected_values):
|
287 |
personalization_prompt = generate_personalization_prompt(*selected_values)
|
|
|
307 |
gigachat_plus_display = f"{personalized_message_gigachat_plus}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
308 |
yield personalization_prompt, gpt4o_display, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, "Все персонализированные сообщения сгенерированы"
|
309 |
|
|
|
310 |
# Функция для генерации промпта проверки текста
|
311 |
def generate_error_check_prompt():
|
312 |
prompt = (
|
|
|
351 |
)
|
352 |
return prompt
|
353 |
|
|
|
354 |
# Функция для выполнения проверки текста с использованием yield
|
355 |
def check_errors_with_yield(*personalized_messages):
|
356 |
if len(personalized_messages) < 4:
|
|
|
378 |
|
379 |
yield error_check_prompt, error_message_gpt4o, error_message_gigachat_pro, error_message_gigachat_lite, error_message_gigachat_plus, "Все результаты проверки сгенерированы"
|
380 |
|
381 |
+
def save_to_github(personalized_message, model_name, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature):
|
|
|
382 |
# Собираем все данные в один словарь
|
383 |
data_to_save = {
|
384 |
"Модель": model_name,
|
385 |
+
"Температура": temperature, # Добавляем температуру
|
386 |
"Персонализированное сообщение": personalized_message,
|
387 |
"Комментарий": comment,
|
388 |
"Откорректированное сообщение": corrected_message,
|
|
|
417 |
# Отправка POST-запроса на GitHub API для создания файла в репозитории
|
418 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
419 |
|
420 |
+
if response.status_code == 201:
|
421 |
+
print("Файл успешно загружен на GitHub.")
|
422 |
+
else:
|
423 |
+
print(f"Ошибка при загрузке файла на GitHub: {response.status_code}")
|
424 |
+
print(f"Ответ сервера: {response.json()}")
|
425 |
|
426 |
# Создание интерфейса Gradio
|
427 |
with gr.Blocks() as demo:
|
428 |
gr.Markdown("# Генерация SMS-сообщений по заданным признакам")
|
429 |
|
430 |
+
# Добавление элементов управления температурой для каждой модели
|
431 |
+
gpt4o_temperature = gr.Slider(label="GPT-4o: temperature", minimum=0, maximum=2, step=0.01, value=1)
|
432 |
+
gigachat_pro_temperature = gr.Slider(label="GigaChat-Pro: temperature", minimum=0, maximum=2, step=0.01, value=0.87)
|
433 |
+
gigachat_lite_temperature = gr.Slider(label="GigaChat-Lite: temperature", minimum=0, maximum=2, step=0.01, value=0.87)
|
434 |
+
gigachat_plus_temperature = gr.Slider(label="GigaChat-Plus: temperature", minimum=0, maximum=2, step=0.01, value=0.87)
|
435 |
+
|
436 |
with gr.Row():
|
437 |
with gr.Column(scale=1):
|
438 |
description_input = gr.Textbox(
|
|
|
472 |
output_text_gigachat_lite = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Lite", lines=3, interactive=False)
|
473 |
output_text_gigachat_plus = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Lite+", lines=3, interactive=False)
|
474 |
|
475 |
+
submit_btn.click(
|
476 |
+
generate_messages,
|
477 |
+
inputs=[
|
478 |
+
description_input,
|
479 |
+
advantages_input,
|
480 |
+
*selections,
|
481 |
+
gpt4o_temperature,
|
482 |
+
gigachat_pro_temperature,
|
483 |
+
gigachat_lite_temperature,
|
484 |
+
gigachat_plus_temperature
|
485 |
+
],
|
486 |
+
outputs=[prompt_display, output_text_gpt4o, output_text_gigachat_pro, output_text_gigachat_lite, output_text_gigachat_plus]
|
487 |
+
)
|
488 |
|
489 |
with gr.Row():
|
490 |
personalize_btn = gr.Button("2. Выполнить персонализацию (нажимать только после кнопки 1)", elem_id="personalize_button")
|
|
|
516 |
corrected_gigachat_lite = gr.Textbox(label="", lines=3)
|
517 |
corrected_gigachat_plus = gr.Textbox(label="", lines=3)
|
518 |
|
|
|
519 |
# Отдельная строка для кнопок с использованием пустой колонки
|
520 |
with gr.Row():
|
521 |
gr.Button("Жми 👍 для сохранения удачного SMS в базу =>")
|
|
|
526 |
|
527 |
# Привязка кнопок к функциям сохранения
|
528 |
save_gpt4o_btn.click(
|
529 |
+
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature:
|
530 |
+
save_to_github(personalized_message, "GPT-4o", comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature),
|
531 |
inputs=[
|
532 |
personalized_output_text_gpt4o,
|
533 |
comment_gpt4o,
|
|
|
541 |
selections[2], # Психотип
|
542 |
selections[3], # Стадия бизнеса
|
543 |
selections[4], # Отрасль
|
544 |
+
selections[5], # ОПФ
|
545 |
+
gpt4o_temperature # Передача температуры
|
546 |
],
|
547 |
outputs=None
|
548 |
)
|
549 |
+
|
550 |
save_gigachat_pro_btn.click(
|
551 |
+
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature:
|
552 |
+
save_to_github(personalized_message, "GigaChat-Pro", comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature),
|
553 |
inputs=[
|
554 |
personalized_output_text_gigachat_pro,
|
555 |
comment_gigachat_pro,
|
|
|
563 |
selections[2], # Психотип
|
564 |
selections[3], # Стадия бизнеса
|
565 |
selections[4], # Отрасль
|
566 |
+
selections[5], # ОПФ
|
567 |
+
gigachat_pro_temperature # Передача температуры
|
568 |
],
|
569 |
outputs=None
|
570 |
)
|
571 |
+
|
572 |
save_gigachat_lite_btn.click(
|
573 |
+
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature:
|
574 |
+
save_to_github(personalized_message, "GigaChat-Lite", comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature),
|
575 |
inputs=[
|
576 |
personalized_output_text_gigachat_lite,
|
577 |
comment_gigachat_lite,
|
|
|
585 |
selections[2], # Психотип
|
586 |
selections[3], # Стадия бизнеса
|
587 |
selections[4], # Отрасль
|
588 |
+
selections[5], # ОПФ
|
589 |
+
gigachat_lite_temperature # Передача температуры
|
590 |
],
|
591 |
outputs=None
|
592 |
)
|
593 |
+
|
594 |
save_gigachat_plus_btn.click(
|
595 |
+
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature:
|
596 |
+
save_to_github(personalized_message, "GigaChat-Plus", comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature),
|
597 |
inputs=[
|
598 |
personalized_output_text_gigachat_plus,
|
599 |
comment_gigachat_plus,
|
|
|
607 |
selections[2], # Психотип
|
608 |
selections[3], # Стадия бизнеса
|
609 |
selections[4], # Отрасль
|
610 |
+
selections[5], # ОПФ
|
611 |
+
gigachat_plus_temperature # Передача температуры
|
612 |
],
|
613 |
outputs=None
|
614 |
)
|
|
|
630 |
]
|
631 |
)
|
632 |
|
|
|
633 |
demo.launch()
|