Spaces:
Sleeping
Sleeping
fruitpicker01
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -335,46 +335,46 @@ def generate_messages(description, advantages, key_message, approach, *selected_
|
|
335 |
|
336 |
results = {
|
337 |
"prompt": standard_prompt,
|
338 |
-
"gpt4o": None,
|
339 |
"gigachat_pro": None,
|
340 |
"gigachat_lite": None,
|
341 |
"gigachat_plus": None,
|
|
|
342 |
"meta_llama_3_1_405b": None
|
343 |
}
|
344 |
|
345 |
yield results["prompt"], "", "", "", "", ""
|
346 |
|
347 |
# Generating messages using existing models (as before)
|
348 |
-
results["gpt4o"] = generate_message_gpt4o_with_retry(standard_prompt)
|
349 |
-
gpt4o_length = len(results["gpt4o"])
|
350 |
-
gpt4o_display = f"{results['gpt4o']}\n\n------\nКоличество знаков: {gpt4o_length}"
|
351 |
-
yield results["prompt"], gpt4o_display, "", "", "", ""
|
352 |
-
|
353 |
results["gigachat_pro"] = generate_message_gigachat_pro_with_retry(standard_prompt)
|
354 |
gigachat_pro_length = len(results["gigachat_pro"])
|
355 |
gigachat_pro_display = f"{results['gigachat_pro']}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
356 |
-
yield results["prompt"],
|
357 |
|
358 |
-
time.sleep(2)
|
359 |
-
|
360 |
results["gigachat_lite"] = generate_message_gigachat_lite_with_retry(standard_prompt)
|
361 |
gigachat_lite_length = len(results["gigachat_lite"])
|
362 |
gigachat_lite_display = f"{results['gigachat_lite']}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
363 |
-
yield results["prompt"],
|
364 |
|
365 |
time.sleep(2)
|
366 |
|
367 |
results["gigachat_plus"] = generate_message_gigachat_plus_with_retry(standard_prompt)
|
368 |
gigachat_plus_length = len(results["gigachat_plus"])
|
369 |
gigachat_plus_display = f"{results['gigachat_plus']}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
370 |
-
yield results["prompt"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
|
372 |
time.sleep(2)
|
373 |
|
374 |
results["meta_llama_3_1_405b"] = generate_message_meta_llama_3_1_405b_with_retry(standard_prompt)
|
375 |
meta_llama_405b_length = len(results["meta_llama_3_1_405b"])
|
376 |
meta_llama_405b_display = f"{results['meta_llama_3_1_405b']}\n\n------\nКоличество знаков: {meta_llama_405b_length}"
|
377 |
-
yield results["prompt"],
|
378 |
|
379 |
time.sleep(2)
|
380 |
|
@@ -467,11 +467,11 @@ def perform_personalization_meta_llama_405b(standard_message, personalization_pr
|
|
467 |
return generate_message_meta_llama_3_1_405b_with_retry(full_prompt)
|
468 |
|
469 |
# Updated function to include additional models in personalization
|
470 |
-
def personalize_messages_with_yield(
|
471 |
-
gpt4o_message,
|
472 |
gigachat_pro_message,
|
473 |
gigachat_lite_message,
|
474 |
-
gigachat_plus_message,
|
|
|
475 |
meta_llama_405b_message,
|
476 |
key_message,
|
477 |
approach,
|
@@ -479,32 +479,32 @@ def personalize_messages_with_yield(
|
|
479 |
):
|
480 |
|
481 |
personalization_prompt = generate_personalization_prompt(key_message, approach, *selected_values)
|
482 |
-
yield personalization_prompt, "", "", "", "", ""
|
483 |
-
|
484 |
-
personalized_message_gpt4o = perform_personalization(gpt4o_message, personalization_prompt)
|
485 |
-
gpt4o_length = len(personalized_message_gpt4o)
|
486 |
-
gpt4o_display = f"{personalized_message_gpt4o}\n\n------\nКоличество знаков: {gpt4o_length}"
|
487 |
-
yield personalization_prompt, gpt4o_display, "", "", "", "", "", "", "", "", ""
|
488 |
|
489 |
personalized_message_gigachat_pro = perform_personalization_gigachat(gigachat_pro_message, personalization_prompt, "gigachat_pro")
|
490 |
gigachat_pro_length = len(personalized_message_gigachat_pro)
|
491 |
gigachat_pro_display = f"{personalized_message_gigachat_pro}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
492 |
-
yield personalization_prompt,
|
493 |
|
494 |
personalized_message_gigachat_lite = perform_personalization_gigachat(gigachat_lite_message, personalization_prompt, "gigachat_lite")
|
495 |
gigachat_lite_length = len(personalized_message_gigachat_lite)
|
496 |
gigachat_lite_display = f"{personalized_message_gigachat_lite}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
497 |
-
yield personalization_prompt,
|
498 |
|
499 |
personalized_message_gigachat_plus = perform_personalization_gigachat(gigachat_plus_message, personalization_prompt, "gigachat_plus")
|
500 |
gigachat_plus_length = len(personalized_message_gigachat_plus)
|
501 |
-
gigachat_plus_display = f"{personalized_message_gigachat_plus}\n\n------\nКоличество знаков: {
|
502 |
-
yield personalization_prompt,
|
|
|
|
|
|
|
|
|
|
|
503 |
|
504 |
personalized_message_meta_llama_405b = perform_personalization_meta_llama_405b(meta_llama_405b_message, personalization_prompt)
|
505 |
meta_llama_405b_length = len(personalized_message_meta_llama_405b)
|
506 |
meta_llama_405b_display = f"{personalized_message_meta_llama_405b}\n\n------\nКоличество знаков: {meta_llama_405b_length}"
|
507 |
-
yield personalization_prompt,
|
508 |
|
509 |
|
510 |
# Функция для генерации промпта проверки текста
|
@@ -594,11 +594,11 @@ def save_to_github(personalized_message, model_name, comment, corrected_message,
|
|
594 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
595 |
|
596 |
|
597 |
-
def personalize_and_save(
|
598 |
-
gpt4o_message,
|
599 |
gigachat_pro_message,
|
600 |
gigachat_lite_message,
|
601 |
-
gigachat_plus_message,
|
|
|
602 |
meta_llama_405b_message,
|
603 |
description,
|
604 |
advantages,
|
@@ -607,11 +607,11 @@ def personalize_and_save(
|
|
607 |
*selected_values
|
608 |
):
|
609 |
# Персонализация с использованием yield для последовательного вывода
|
610 |
-
personalization_generator = personalize_messages_with_yield(
|
611 |
-
gpt4o_message,
|
612 |
gigachat_pro_message,
|
613 |
gigachat_lite_message,
|
614 |
-
gigachat_plus_message,
|
|
|
615 |
meta_llama_405b_message,
|
616 |
key_message,
|
617 |
approach,
|
@@ -788,58 +788,58 @@ with gr.Blocks() as demo:
|
|
788 |
|
789 |
# Ряд кнопок "Перегенерировать"
|
790 |
with gr.Row():
|
791 |
-
regen_gpt4o_btn = gr.Button("Перегенерировать")
|
792 |
regen_gigachat_pro_btn = gr.Button("Перегенерировать")
|
793 |
regen_gigachat_lite_btn = gr.Button("Перегенерировать")
|
794 |
regen_gigachat_plus_btn = gr.Button("Перегенерировать")
|
|
|
795 |
regen_meta_llama_405b_btn = gr.Button("Перегенерировать")
|
796 |
|
797 |
# Первый ряд: неперсонализированные сообщения
|
798 |
with gr.Row():
|
799 |
-
output_text_gpt4o = gr.Textbox(label="Неперсонализированное сообщение GPT-4o", lines=3, interactive=False)
|
800 |
output_text_gigachat_pro = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Pro", lines=3, interactive=False)
|
801 |
output_text_gigachat_lite = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Lite", lines=3, interactive=False)
|
802 |
-
output_text_gigachat_plus = gr.Textbox(label="Неперсонализированное сообщение GigaChat-
|
|
|
803 |
output_text_meta_llama_405b = gr.Textbox(label="Неперсонализированное сообщение Meta-Llama-3.1-405B", lines=3, interactive=False)
|
804 |
|
805 |
# Ряд кнопок "Персонализировать"
|
806 |
with gr.Row():
|
807 |
-
personalize_gpt4o_btn = gr.Button("Персонализировать")
|
808 |
personalize_gigachat_pro_btn = gr.Button("Персонализировать")
|
809 |
personalize_gigachat_lite_btn = gr.Button("Персонализировать")
|
810 |
personalize_gigachat_plus_btn = gr.Button("Персонализировать")
|
|
|
811 |
personalize_meta_llama_405b_btn = gr.Button("Персонализировать")
|
812 |
|
813 |
# Второй ряд: персонализированные сообщения
|
814 |
with gr.Row():
|
815 |
-
personalized_output_text_gpt4o = gr.Textbox(label="Персонализированное сообщение GPT-4o", lines=3, interactive=False)
|
816 |
personalized_output_text_gigachat_pro = gr.Textbox(label="Персонализированное сообщение GigaChat-Pro", lines=3, interactive=False)
|
817 |
personalized_output_text_gigachat_lite = gr.Textbox(label="Персонализированное сообщение GigaChat-Lite", lines=3, interactive=False)
|
818 |
-
personalized_output_text_gigachat_plus = gr.Textbox(label="Персонализированное сообщение GigaChat-
|
|
|
819 |
personalized_output_text_meta_llama_405b = gr.Textbox(label="Персонализированное сообщение Meta-Llama-3.1-405B", lines=3, interactive=False)
|
820 |
|
821 |
# Третий ряд: комментарии
|
822 |
with gr.Row():
|
823 |
-
comment_gpt4o = gr.Textbox(label="Комментарий к сообщению GPT-4o", lines=3)
|
824 |
comment_gigachat_pro = gr.Textbox(label="Комментарий к сообщению GigaChat-Pro", lines=3)
|
825 |
comment_gigachat_lite = gr.Textbox(label="Комментарий к сообщению GigaChat-Lite", lines=3)
|
826 |
-
comment_gigachat_plus = gr.Textbox(label="Комментарий к сообщению GigaChat-
|
|
|
827 |
comment_meta_llama_405b = gr.Textbox(label="Комментарий к сообщению Meta-Llama-3.1-405B", lines=3)
|
828 |
|
829 |
# Четвертый ряд: откорректированные сообщения
|
830 |
with gr.Row():
|
831 |
-
corrected_gpt4o = gr.Textbox(label="Откорректированное сообщение GPT-4o", lines=3)
|
832 |
corrected_gigachat_pro = gr.Textbox(label="Откорректированное сообщение GigaChat-Pro", lines=3)
|
833 |
corrected_gigachat_lite = gr.Textbox(label="Откорректированное сообщение GigaChat-Lite", lines=3)
|
834 |
-
corrected_gigachat_plus = gr.Textbox(label="Откорректированное сообщение GigaChat-
|
|
|
835 |
corrected_meta_llama_405b = gr.Textbox(label="Откорректированное сообщение Meta-Llama-3.1-405B", lines=3)
|
836 |
|
837 |
# Пятый ряд: кнопки сохранения
|
838 |
with gr.Row():
|
839 |
-
save_gpt4o_btn = gr.Button("Сохранить в базу")
|
840 |
save_gigachat_pro_btn = gr.Button("Сохранить в базу")
|
841 |
save_gigachat_lite_btn = gr.Button("Сохранить в базу")
|
842 |
save_gigachat_plus_btn = gr.Button("Сохранить в базу")
|
|
|
843 |
save_meta_llama_405b_btn = gr.Button("Сохранить в базу")
|
844 |
|
845 |
|
@@ -849,19 +849,19 @@ with gr.Blocks() as demo:
|
|
849 |
inputs=[],
|
850 |
outputs=[
|
851 |
personalization_prompt,
|
852 |
-
personalized_output_text_gpt4o,
|
853 |
personalized_output_text_gigachat_pro,
|
854 |
personalized_output_text_gigachat_lite,
|
855 |
personalized_output_text_gigachat_plus,
|
|
|
856 |
personalized_output_text_meta_llama_405b,
|
857 |
-
comment_gpt4o,
|
858 |
-
corrected_gpt4o,
|
859 |
comment_gigachat_pro,
|
860 |
corrected_gigachat_pro,
|
861 |
comment_gigachat_lite,
|
862 |
corrected_gigachat_lite,
|
863 |
comment_gigachat_plus,
|
864 |
corrected_gigachat_plus,
|
|
|
|
|
865 |
comment_meta_llama_405b,
|
866 |
corrected_meta_llama_405b
|
867 |
]
|
@@ -871,11 +871,11 @@ with gr.Blocks() as demo:
|
|
871 |
generate_messages,
|
872 |
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
873 |
outputs=[
|
874 |
-
prompt_display,
|
875 |
-
output_text_gpt4o,
|
876 |
output_text_gigachat_pro,
|
877 |
output_text_gigachat_lite,
|
878 |
-
output_text_gigachat_plus,
|
|
|
879 |
output_text_meta_llama_405b
|
880 |
]
|
881 |
)
|
@@ -885,19 +885,19 @@ with gr.Blocks() as demo:
|
|
885 |
fn=clear_personalization_fields,
|
886 |
inputs=[],
|
887 |
outputs=[
|
888 |
-
personalized_output_text_gpt4o,
|
889 |
personalized_output_text_gigachat_pro,
|
890 |
personalized_output_text_gigachat_lite,
|
891 |
personalized_output_text_gigachat_plus,
|
|
|
892 |
personalized_output_text_meta_llama_405b,
|
893 |
-
comment_gpt4o,
|
894 |
-
corrected_gpt4o,
|
895 |
comment_gigachat_pro,
|
896 |
corrected_gigachat_pro,
|
897 |
comment_gigachat_lite,
|
898 |
corrected_gigachat_lite,
|
899 |
comment_gigachat_plus,
|
900 |
corrected_gigachat_plus,
|
|
|
|
|
901 |
comment_meta_llama_405b,
|
902 |
corrected_meta_llama_405b
|
903 |
]
|
@@ -905,11 +905,11 @@ with gr.Blocks() as demo:
|
|
905 |
|
906 |
personalize_btn.click(
|
907 |
fn=personalize_and_save,
|
908 |
-
inputs=[
|
909 |
-
output_text_gpt4o,
|
910 |
output_text_gigachat_pro,
|
911 |
output_text_gigachat_lite,
|
912 |
-
output_text_gigachat_plus,
|
|
|
913 |
output_text_meta_llama_405b,
|
914 |
description_input,
|
915 |
advantages_input,
|
@@ -918,10 +918,10 @@ with gr.Blocks() as demo:
|
|
918 |
] + selections,
|
919 |
outputs=[
|
920 |
personalization_prompt,
|
921 |
-
personalized_output_text_gpt4o,
|
922 |
personalized_output_text_gigachat_pro,
|
923 |
personalized_output_text_gigachat_lite,
|
924 |
personalized_output_text_gigachat_plus,
|
|
|
925 |
personalized_output_text_meta_llama_405b
|
926 |
]
|
927 |
)
|
@@ -943,35 +943,29 @@ with gr.Blocks() as demo:
|
|
943 |
outputs=[
|
944 |
prompt_display,
|
945 |
personalization_prompt, # Очищаем personalization_prompt
|
946 |
-
output_text_gpt4o,
|
947 |
output_text_gigachat_pro,
|
948 |
output_text_gigachat_lite,
|
949 |
output_text_gigachat_plus,
|
|
|
950 |
output_text_meta_llama_405b,
|
951 |
-
personalized_output_text_gpt4o,
|
952 |
personalized_output_text_gigachat_pro,
|
953 |
personalized_output_text_gigachat_lite,
|
954 |
personalized_output_text_gigachat_plus,
|
|
|
955 |
personalized_output_text_meta_llama_405b,
|
956 |
-
comment_gpt4o,
|
957 |
-
corrected_gpt4o,
|
958 |
comment_gigachat_pro,
|
959 |
corrected_gigachat_pro,
|
960 |
comment_gigachat_lite,
|
961 |
corrected_gigachat_lite,
|
962 |
comment_gigachat_plus,
|
963 |
corrected_gigachat_plus,
|
|
|
|
|
964 |
comment_meta_llama_405b,
|
965 |
corrected_meta_llama_405b
|
966 |
]
|
967 |
)
|
968 |
|
969 |
-
regen_gpt4o_btn.click(
|
970 |
-
regen_message_gpt4o,
|
971 |
-
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
972 |
-
outputs=output_text_gpt4o
|
973 |
-
)
|
974 |
-
|
975 |
regen_gigachat_pro_btn.click(
|
976 |
regen_message_gigachat_pro,
|
977 |
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
@@ -989,19 +983,19 @@ with gr.Blocks() as demo:
|
|
989 |
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
990 |
outputs=output_text_gigachat_plus
|
991 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
992 |
|
993 |
regen_meta_llama_405b_btn.click(
|
994 |
regen_message_meta_llama_405b,
|
995 |
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
996 |
outputs=output_text_meta_llama_405b
|
997 |
)
|
998 |
-
|
999 |
-
personalize_gpt4o_btn.click(
|
1000 |
-
personalize_message_gpt4o,
|
1001 |
-
inputs=[output_text_gpt4o, key_message_input, approach_input] + selections,
|
1002 |
-
outputs=personalized_output_text_gpt4o
|
1003 |
-
)
|
1004 |
-
|
1005 |
personalize_gigachat_pro_btn.click(
|
1006 |
personalize_message_gigachat_pro,
|
1007 |
inputs=[output_text_gigachat_pro, key_message_input, approach_input] + selections,
|
@@ -1019,6 +1013,12 @@ with gr.Blocks() as demo:
|
|
1019 |
inputs=[output_text_gigachat_plus, key_message_input, approach_input] + selections,
|
1020 |
outputs=personalized_output_text_gigachat_plus
|
1021 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
1022 |
|
1023 |
personalize_meta_llama_405b_btn.click(
|
1024 |
personalize_message_meta_llama_405b,
|
@@ -1026,43 +1026,7 @@ with gr.Blocks() as demo:
|
|
1026 |
outputs=personalized_output_text_meta_llama_405b
|
1027 |
)
|
1028 |
|
1029 |
-
# Привязка кнопок к функциям сохранения
|
1030 |
-
save_gpt4o_btn.click(
|
1031 |
-
fn=prepare_button_text, # Сначала меняем текст на "Сохраняется..."
|
1032 |
-
inputs=[],
|
1033 |
-
outputs=[save_gpt4o_btn]
|
1034 |
-
).then(
|
1035 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form, key_message, approach:
|
1036 |
-
save_to_github(personalized_message, "GPT-4o", comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form, key_message, approach),
|
1037 |
-
inputs=[
|
1038 |
-
personalized_output_text_gpt4o,
|
1039 |
-
comment_gpt4o,
|
1040 |
-
corrected_gpt4o,
|
1041 |
-
description_input,
|
1042 |
-
advantages_input,
|
1043 |
-
prompt_display,
|
1044 |
-
output_text_gpt4o,
|
1045 |
-
personalization_prompt,
|
1046 |
-
selections[0], # Пол
|
1047 |
-
selections[1], # Поколение
|
1048 |
-
selections[2], # Психотип
|
1049 |
-
selections[3], # Стадия бизнеса
|
1050 |
-
selections[4], # Отрасль
|
1051 |
-
selections[5], # ОПФ
|
1052 |
-
key_message_input, # Ключевое сообщение
|
1053 |
-
approach_input # Подход
|
1054 |
-
],
|
1055 |
-
outputs=None
|
1056 |
-
).then(
|
1057 |
-
fn=update_button_text, # Обновляем текст на "Сохранено!" после сохранения
|
1058 |
-
outputs=[save_gpt4o_btn]
|
1059 |
-
).then(
|
1060 |
-
fn=reset_button_text, # Возвращаем текст на кнопке обратно через 3 секунды
|
1061 |
-
outputs=[save_gpt4o_btn]
|
1062 |
-
)
|
1063 |
-
|
1064 |
-
# То же самое для других кнопок:
|
1065 |
-
|
1066 |
save_gigachat_pro_btn.click(
|
1067 |
fn=prepare_button_text,
|
1068 |
inputs=[],
|
@@ -1166,6 +1130,40 @@ with gr.Blocks() as demo:
|
|
1166 |
fn=reset_button_text,
|
1167 |
outputs=[save_gigachat_plus_btn]
|
1168 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1169 |
|
1170 |
save_meta_llama_405b_btn.click(
|
1171 |
fn=prepare_button_text,
|
|
|
335 |
|
336 |
results = {
|
337 |
"prompt": standard_prompt,
|
|
|
338 |
"gigachat_pro": None,
|
339 |
"gigachat_lite": None,
|
340 |
"gigachat_plus": None,
|
341 |
+
"gpt4o": None,
|
342 |
"meta_llama_3_1_405b": None
|
343 |
}
|
344 |
|
345 |
yield results["prompt"], "", "", "", "", ""
|
346 |
|
347 |
# Generating messages using existing models (as before)
|
|
|
|
|
|
|
|
|
|
|
348 |
results["gigachat_pro"] = generate_message_gigachat_pro_with_retry(standard_prompt)
|
349 |
gigachat_pro_length = len(results["gigachat_pro"])
|
350 |
gigachat_pro_display = f"{results['gigachat_pro']}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
351 |
+
yield results["prompt"], gigachat_pro_display, "", "", "", ""
|
352 |
|
|
|
|
|
353 |
results["gigachat_lite"] = generate_message_gigachat_lite_with_retry(standard_prompt)
|
354 |
gigachat_lite_length = len(results["gigachat_lite"])
|
355 |
gigachat_lite_display = f"{results['gigachat_lite']}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
356 |
+
yield results["prompt"], gigachat_pro_display, gigachat_lite_display, "", "", ""
|
357 |
|
358 |
time.sleep(2)
|
359 |
|
360 |
results["gigachat_plus"] = generate_message_gigachat_plus_with_retry(standard_prompt)
|
361 |
gigachat_plus_length = len(results["gigachat_plus"])
|
362 |
gigachat_plus_display = f"{results['gigachat_plus']}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
363 |
+
yield results["prompt"], gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, "", ""
|
364 |
+
|
365 |
+
time.sleep(2)
|
366 |
+
|
367 |
+
results["gpt4o"] = generate_message_gpt4o_with_retry(standard_prompt)
|
368 |
+
gpt4o_length = len(results["gpt4o"])
|
369 |
+
gpt4o_display = f"{results['gpt4o']}\n\n------\nКоличество знаков: {gpt4o_length}"
|
370 |
+
yield results["prompt"], gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, gpt4o_display, ""
|
371 |
|
372 |
time.sleep(2)
|
373 |
|
374 |
results["meta_llama_3_1_405b"] = generate_message_meta_llama_3_1_405b_with_retry(standard_prompt)
|
375 |
meta_llama_405b_length = len(results["meta_llama_3_1_405b"])
|
376 |
meta_llama_405b_display = f"{results['meta_llama_3_1_405b']}\n\n------\nКоличество знаков: {meta_llama_405b_length}"
|
377 |
+
yield results["prompt"], gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, gpt4o_display, meta_llama_405b_display
|
378 |
|
379 |
time.sleep(2)
|
380 |
|
|
|
467 |
return generate_message_meta_llama_3_1_405b_with_retry(full_prompt)
|
468 |
|
469 |
# Updated function to include additional models in personalization
|
470 |
+
def personalize_messages_with_yield(
|
|
|
471 |
gigachat_pro_message,
|
472 |
gigachat_lite_message,
|
473 |
+
gigachat_plus_message,
|
474 |
+
gpt4o_message,
|
475 |
meta_llama_405b_message,
|
476 |
key_message,
|
477 |
approach,
|
|
|
479 |
):
|
480 |
|
481 |
personalization_prompt = generate_personalization_prompt(key_message, approach, *selected_values)
|
482 |
+
yield personalization_prompt, "", "", "", "", ""
|
|
|
|
|
|
|
|
|
|
|
483 |
|
484 |
personalized_message_gigachat_pro = perform_personalization_gigachat(gigachat_pro_message, personalization_prompt, "gigachat_pro")
|
485 |
gigachat_pro_length = len(personalized_message_gigachat_pro)
|
486 |
gigachat_pro_display = f"{personalized_message_gigachat_pro}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
487 |
+
yield personalization_prompt, gigachat_pro_display, "", "", "", ""
|
488 |
|
489 |
personalized_message_gigachat_lite = perform_personalization_gigachat(gigachat_lite_message, personalization_prompt, "gigachat_lite")
|
490 |
gigachat_lite_length = len(personalized_message_gigachat_lite)
|
491 |
gigachat_lite_display = f"{personalized_message_gigachat_lite}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
492 |
+
yield personalization_prompt, gigachat_pro_display, gigachat_lite_display, "", "", ""
|
493 |
|
494 |
personalized_message_gigachat_plus = perform_personalization_gigachat(gigachat_plus_message, personalization_prompt, "gigachat_plus")
|
495 |
gigachat_plus_length = len(personalized_message_gigachat_plus)
|
496 |
+
gigachat_plus_display = f"{personalized_message_gigachat_plus}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
497 |
+
yield personalization_prompt, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, "", ""
|
498 |
+
|
499 |
+
personalized_message_gpt4o = perform_personalization(gpt4o_message, personalization_prompt)
|
500 |
+
gpt4o_length = len(personalized_message_gpt4o)
|
501 |
+
gpt4o_display = f"{personalized_message_gpt4o}\n\n------\nКоличество знаков: {gpt4o_length}"
|
502 |
+
yield personalization_prompt, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, gpt4o_display, ""
|
503 |
|
504 |
personalized_message_meta_llama_405b = perform_personalization_meta_llama_405b(meta_llama_405b_message, personalization_prompt)
|
505 |
meta_llama_405b_length = len(personalized_message_meta_llama_405b)
|
506 |
meta_llama_405b_display = f"{personalized_message_meta_llama_405b}\n\n------\nКоличество знаков: {meta_llama_405b_length}"
|
507 |
+
yield personalization_prompt, gigachat_pro_display, gigachat_lite_display, gigachat_plus_display, gpt4o_display, meta_llama_405b_display
|
508 |
|
509 |
|
510 |
# Функция для генерации промпта проверки текста
|
|
|
594 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
595 |
|
596 |
|
597 |
+
def personalize_and_save(
|
|
|
598 |
gigachat_pro_message,
|
599 |
gigachat_lite_message,
|
600 |
+
gigachat_plus_message,
|
601 |
+
gpt4o_message,
|
602 |
meta_llama_405b_message,
|
603 |
description,
|
604 |
advantages,
|
|
|
607 |
*selected_values
|
608 |
):
|
609 |
# Персонализация с использованием yield для последовательного вывода
|
610 |
+
personalization_generator = personalize_messages_with_yield(
|
|
|
611 |
gigachat_pro_message,
|
612 |
gigachat_lite_message,
|
613 |
+
gigachat_plus_message,
|
614 |
+
gpt4o_message,
|
615 |
meta_llama_405b_message,
|
616 |
key_message,
|
617 |
approach,
|
|
|
788 |
|
789 |
# Ряд кнопок "Перегенерировать"
|
790 |
with gr.Row():
|
|
|
791 |
regen_gigachat_pro_btn = gr.Button("Перегенерировать")
|
792 |
regen_gigachat_lite_btn = gr.Button("Перегенерировать")
|
793 |
regen_gigachat_plus_btn = gr.Button("Перегенерировать")
|
794 |
+
regen_gpt4o_btn = gr.Button("Перегенерировать")
|
795 |
regen_meta_llama_405b_btn = gr.Button("Перегенерировать")
|
796 |
|
797 |
# Первый ряд: неперсонализированные сообщения
|
798 |
with gr.Row():
|
|
|
799 |
output_text_gigachat_pro = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Pro", lines=3, interactive=False)
|
800 |
output_text_gigachat_lite = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Lite", lines=3, interactive=False)
|
801 |
+
output_text_gigachat_plus = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Lite+", lines=3, interactive=False)
|
802 |
+
output_text_gpt4o = gr.Textbox(label="Неперсонализированное сообщение GPT-4o", lines=3, interactive=False)
|
803 |
output_text_meta_llama_405b = gr.Textbox(label="Неперсонализированное сообщение Meta-Llama-3.1-405B", lines=3, interactive=False)
|
804 |
|
805 |
# Ряд кнопок "Персонализировать"
|
806 |
with gr.Row():
|
|
|
807 |
personalize_gigachat_pro_btn = gr.Button("Персонализировать")
|
808 |
personalize_gigachat_lite_btn = gr.Button("Персонализировать")
|
809 |
personalize_gigachat_plus_btn = gr.Button("Персонализировать")
|
810 |
+
personalize_gpt4o_btn = gr.Button("Персонализировать")
|
811 |
personalize_meta_llama_405b_btn = gr.Button("Персонализировать")
|
812 |
|
813 |
# Второй ряд: персонализированные сообщения
|
814 |
with gr.Row():
|
|
|
815 |
personalized_output_text_gigachat_pro = gr.Textbox(label="Персонализированное сообщение GigaChat-Pro", lines=3, interactive=False)
|
816 |
personalized_output_text_gigachat_lite = gr.Textbox(label="Персонализированное сообщение GigaChat-Lite", lines=3, interactive=False)
|
817 |
+
personalized_output_text_gigachat_plus = gr.Textbox(label="Персонализированное сообщение GigaChat-Lite+", lines=3, interactive=False)
|
818 |
+
personalized_output_text_gpt4o = gr.Textbox(label="Персонализированное сообщение GPT-4o", lines=3, interactive=False)
|
819 |
personalized_output_text_meta_llama_405b = gr.Textbox(label="Персонализированное сообщение Meta-Llama-3.1-405B", lines=3, interactive=False)
|
820 |
|
821 |
# Третий ряд: комментарии
|
822 |
with gr.Row():
|
|
|
823 |
comment_gigachat_pro = gr.Textbox(label="Комментарий к сообщению GigaChat-Pro", lines=3)
|
824 |
comment_gigachat_lite = gr.Textbox(label="Комментарий к сообщению GigaChat-Lite", lines=3)
|
825 |
+
comment_gigachat_plus = gr.Textbox(label="Комментарий к сообщению GigaChat-Lite+", lines=3)
|
826 |
+
comment_gpt4o = gr.Textbox(label="Комментарий к сообщению GPT-4o", lines=3)
|
827 |
comment_meta_llama_405b = gr.Textbox(label="Комментарий к сообщению Meta-Llama-3.1-405B", lines=3)
|
828 |
|
829 |
# Четвертый ряд: откорректированные сообщения
|
830 |
with gr.Row():
|
|
|
831 |
corrected_gigachat_pro = gr.Textbox(label="Откорректированное сообщение GigaChat-Pro", lines=3)
|
832 |
corrected_gigachat_lite = gr.Textbox(label="Откорректированное сообщение GigaChat-Lite", lines=3)
|
833 |
+
corrected_gigachat_plus = gr.Textbox(label="Откорректированное сообщение GigaChat-Lite+", lines=3)
|
834 |
+
corrected_gpt4o = gr.Textbox(label="Откорректированное сообщение GPT-4o", lines=3)
|
835 |
corrected_meta_llama_405b = gr.Textbox(label="Откорректированное сообщение Meta-Llama-3.1-405B", lines=3)
|
836 |
|
837 |
# Пятый ряд: кнопки сохранения
|
838 |
with gr.Row():
|
|
|
839 |
save_gigachat_pro_btn = gr.Button("Сохранить в базу")
|
840 |
save_gigachat_lite_btn = gr.Button("Сохранить в базу")
|
841 |
save_gigachat_plus_btn = gr.Button("Сохранить в базу")
|
842 |
+
save_gpt4o_btn = gr.Button("Сохранить в базу")
|
843 |
save_meta_llama_405b_btn = gr.Button("Сохранить в базу")
|
844 |
|
845 |
|
|
|
849 |
inputs=[],
|
850 |
outputs=[
|
851 |
personalization_prompt,
|
|
|
852 |
personalized_output_text_gigachat_pro,
|
853 |
personalized_output_text_gigachat_lite,
|
854 |
personalized_output_text_gigachat_plus,
|
855 |
+
personalized_output_text_gpt4o,
|
856 |
personalized_output_text_meta_llama_405b,
|
|
|
|
|
857 |
comment_gigachat_pro,
|
858 |
corrected_gigachat_pro,
|
859 |
comment_gigachat_lite,
|
860 |
corrected_gigachat_lite,
|
861 |
comment_gigachat_plus,
|
862 |
corrected_gigachat_plus,
|
863 |
+
comment_gpt4o,
|
864 |
+
corrected_gpt4o,
|
865 |
comment_meta_llama_405b,
|
866 |
corrected_meta_llama_405b
|
867 |
]
|
|
|
871 |
generate_messages,
|
872 |
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
873 |
outputs=[
|
874 |
+
prompt_display,
|
|
|
875 |
output_text_gigachat_pro,
|
876 |
output_text_gigachat_lite,
|
877 |
+
output_text_gigachat_plus,
|
878 |
+
output_text_gpt4o,
|
879 |
output_text_meta_llama_405b
|
880 |
]
|
881 |
)
|
|
|
885 |
fn=clear_personalization_fields,
|
886 |
inputs=[],
|
887 |
outputs=[
|
|
|
888 |
personalized_output_text_gigachat_pro,
|
889 |
personalized_output_text_gigachat_lite,
|
890 |
personalized_output_text_gigachat_plus,
|
891 |
+
personalized_output_text_gpt4o,
|
892 |
personalized_output_text_meta_llama_405b,
|
|
|
|
|
893 |
comment_gigachat_pro,
|
894 |
corrected_gigachat_pro,
|
895 |
comment_gigachat_lite,
|
896 |
corrected_gigachat_lite,
|
897 |
comment_gigachat_plus,
|
898 |
corrected_gigachat_plus,
|
899 |
+
comment_gpt4o,
|
900 |
+
corrected_gpt4o,
|
901 |
comment_meta_llama_405b,
|
902 |
corrected_meta_llama_405b
|
903 |
]
|
|
|
905 |
|
906 |
personalize_btn.click(
|
907 |
fn=personalize_and_save,
|
908 |
+
inputs=[
|
|
|
909 |
output_text_gigachat_pro,
|
910 |
output_text_gigachat_lite,
|
911 |
+
output_text_gigachat_plus,
|
912 |
+
output_text_gpt4o,
|
913 |
output_text_meta_llama_405b,
|
914 |
description_input,
|
915 |
advantages_input,
|
|
|
918 |
] + selections,
|
919 |
outputs=[
|
920 |
personalization_prompt,
|
|
|
921 |
personalized_output_text_gigachat_pro,
|
922 |
personalized_output_text_gigachat_lite,
|
923 |
personalized_output_text_gigachat_plus,
|
924 |
+
personalized_output_text_gpt4o,
|
925 |
personalized_output_text_meta_llama_405b
|
926 |
]
|
927 |
)
|
|
|
943 |
outputs=[
|
944 |
prompt_display,
|
945 |
personalization_prompt, # Очищаем personalization_prompt
|
|
|
946 |
output_text_gigachat_pro,
|
947 |
output_text_gigachat_lite,
|
948 |
output_text_gigachat_plus,
|
949 |
+
output_text_gpt4o,
|
950 |
output_text_meta_llama_405b,
|
|
|
951 |
personalized_output_text_gigachat_pro,
|
952 |
personalized_output_text_gigachat_lite,
|
953 |
personalized_output_text_gigachat_plus,
|
954 |
+
personalized_output_text_gpt4o,
|
955 |
personalized_output_text_meta_llama_405b,
|
|
|
|
|
956 |
comment_gigachat_pro,
|
957 |
corrected_gigachat_pro,
|
958 |
comment_gigachat_lite,
|
959 |
corrected_gigachat_lite,
|
960 |
comment_gigachat_plus,
|
961 |
corrected_gigachat_plus,
|
962 |
+
comment_gpt4o,
|
963 |
+
corrected_gpt4o,
|
964 |
comment_meta_llama_405b,
|
965 |
corrected_meta_llama_405b
|
966 |
]
|
967 |
)
|
968 |
|
|
|
|
|
|
|
|
|
|
|
|
|
969 |
regen_gigachat_pro_btn.click(
|
970 |
regen_message_gigachat_pro,
|
971 |
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
|
|
983 |
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
984 |
outputs=output_text_gigachat_plus
|
985 |
)
|
986 |
+
|
987 |
+
regen_gpt4o_btn.click(
|
988 |
+
regen_message_gpt4o,
|
989 |
+
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
990 |
+
outputs=output_text_gpt4o
|
991 |
+
)
|
992 |
|
993 |
regen_meta_llama_405b_btn.click(
|
994 |
regen_message_meta_llama_405b,
|
995 |
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
996 |
outputs=output_text_meta_llama_405b
|
997 |
)
|
998 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
999 |
personalize_gigachat_pro_btn.click(
|
1000 |
personalize_message_gigachat_pro,
|
1001 |
inputs=[output_text_gigachat_pro, key_message_input, approach_input] + selections,
|
|
|
1013 |
inputs=[output_text_gigachat_plus, key_message_input, approach_input] + selections,
|
1014 |
outputs=personalized_output_text_gigachat_plus
|
1015 |
)
|
1016 |
+
|
1017 |
+
personalize_gpt4o_btn.click(
|
1018 |
+
personalize_message_gpt4o,
|
1019 |
+
inputs=[output_text_gpt4o, key_message_input, approach_input] + selections,
|
1020 |
+
outputs=personalized_output_text_gpt4o
|
1021 |
+
)
|
1022 |
|
1023 |
personalize_meta_llama_405b_btn.click(
|
1024 |
personalize_message_meta_llama_405b,
|
|
|
1026 |
outputs=personalized_output_text_meta_llama_405b
|
1027 |
)
|
1028 |
|
1029 |
+
# Привязка кнопок к функциям сохранения
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1030 |
save_gigachat_pro_btn.click(
|
1031 |
fn=prepare_button_text,
|
1032 |
inputs=[],
|
|
|
1130 |
fn=reset_button_text,
|
1131 |
outputs=[save_gigachat_plus_btn]
|
1132 |
)
|
1133 |
+
|
1134 |
+
save_gpt4o_btn.click(
|
1135 |
+
fn=prepare_button_text, # Сначала меняем текст на "Сохраняется..."
|
1136 |
+
inputs=[],
|
1137 |
+
outputs=[save_gpt4o_btn]
|
1138 |
+
).then(
|
1139 |
+
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form, key_message, approach:
|
1140 |
+
save_to_github(personalized_message, "GPT-4o", comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form, key_message, approach),
|
1141 |
+
inputs=[
|
1142 |
+
personalized_output_text_gpt4o,
|
1143 |
+
comment_gpt4o,
|
1144 |
+
corrected_gpt4o,
|
1145 |
+
description_input,
|
1146 |
+
advantages_input,
|
1147 |
+
prompt_display,
|
1148 |
+
output_text_gpt4o,
|
1149 |
+
personalization_prompt,
|
1150 |
+
selections[0], # Пол
|
1151 |
+
selections[1], # Поколение
|
1152 |
+
selections[2], # Психотип
|
1153 |
+
selections[3], # Стадия бизнеса
|
1154 |
+
selections[4], # Отрасль
|
1155 |
+
selections[5], # ОПФ
|
1156 |
+
key_message_input, # Ключевое сообщение
|
1157 |
+
approach_input # Подход
|
1158 |
+
],
|
1159 |
+
outputs=None
|
1160 |
+
).then(
|
1161 |
+
fn=update_button_text, # Обновляем текст на "Сохранено!" после сохранения
|
1162 |
+
outputs=[save_gpt4o_btn]
|
1163 |
+
).then(
|
1164 |
+
fn=reset_button_text, # Возвращаем текст на кнопке обратно через 3 секунды
|
1165 |
+
outputs=[save_gpt4o_btn]
|
1166 |
+
)
|
1167 |
|
1168 |
save_meta_llama_405b_btn.click(
|
1169 |
fn=prepare_button_text,
|