Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -664,6 +664,66 @@ def clear_unnecessary_fields():
|
|
664 |
"", "" # Дополнительное пустое значение
|
665 |
)
|
666 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
|
668 |
# Создание интерфейса Gradio
|
669 |
with gr.Blocks() as demo:
|
@@ -723,7 +783,14 @@ with gr.Blocks() as demo:
|
|
723 |
personalize_btn = gr.Button("2. Выполнить персонализацию (нажимать только после кнопки 1)", elem_id="personalize_button")
|
724 |
load_btn = gr.Button("Вернуть параметры предыдущего запроса")
|
725 |
|
726 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
727 |
# Первый ряд: неперсонализированные сообщения
|
728 |
with gr.Row():
|
729 |
output_text_gpt4o = gr.Textbox(label="Неперсонализированное сообщение GPT-4o", lines=3, interactive=False)
|
@@ -731,6 +798,14 @@ with gr.Blocks() as demo:
|
|
731 |
output_text_gigachat_lite = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Lite", lines=3, interactive=False)
|
732 |
output_text_gigachat_plus = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Plus", lines=3, interactive=False)
|
733 |
output_text_meta_llama_405b = gr.Textbox(label="Неперсонализированное сообщение Meta-Llama-3.1-405B", lines=3, interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
734 |
|
735 |
# Второй ряд: персонализированные сообщения
|
736 |
with gr.Row():
|
@@ -888,6 +963,65 @@ with gr.Blocks() as demo:
|
|
888 |
]
|
889 |
)
|
890 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
891 |
|
892 |
# Привязка кнопок к функциям сохранения
|
893 |
save_gpt4o_btn.click(
|
|
|
664 |
"", "" # Дополнительное пустое значение
|
665 |
)
|
666 |
|
667 |
+
def regen_message_gpt4o(description, advantages, key_message, approach, *selected_values):
|
668 |
+
standard_prompt = generate_standard_prompt(description, advantages, key_message, approach, *selected_values)
|
669 |
+
gpt4o_message = generate_message_gpt4o_with_retry(standard_prompt)
|
670 |
+
gpt4o_length = len(gpt4o_message)
|
671 |
+
return f"{gpt4o_message}\n\n------\nКоличество знаков: {gpt4o_length}"
|
672 |
+
|
673 |
+
def regen_message_gigachat_pro(description, advantages, key_message, approach, *selected_values):
|
674 |
+
standard_prompt = generate_standard_prompt(description, advantages, key_message, approach, *selected_values)
|
675 |
+
gigachat_pro_message = generate_message_gigachat_pro_with_retry(standard_prompt)
|
676 |
+
gigachat_pro_length = len(gigachat_pro_message)
|
677 |
+
return f"{gigachat_pro_message}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
678 |
+
|
679 |
+
def regen_message_gigachat_lite(description, advantages, key_message, approach, *selected_values):
|
680 |
+
standard_prompt = generate_standard_prompt(description, advantages, key_message, approach, *selected_values)
|
681 |
+
gigachat_lite_message = generate_message_gigachat_lite_with_retry(standard_prompt)
|
682 |
+
gigachat_lite_length = len(gigachat_lite_message)
|
683 |
+
return f"{gigachat_lite_message}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
684 |
+
|
685 |
+
def regen_message_gigachat_plus(description, advantages, key_message, approach, *selected_values):
|
686 |
+
standard_prompt = generate_standard_prompt(description, advantages, key_message, approach, *selected_values)
|
687 |
+
gigachat_plus_message = generate_message_gigachat_plus_with_retry(standard_prompt)
|
688 |
+
gigachat_plus_length = len(gigachat_plus_message)
|
689 |
+
return f"{gigachat_plus_message}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
690 |
+
|
691 |
+
def regen_message_meta_llama_405b(description, advantages, key_message, approach, *selected_values):
|
692 |
+
standard_prompt = generate_standard_prompt(description, advantages, key_message, approach, *selected_values)
|
693 |
+
meta_llama_405b_message = generate_message_meta_llama_3_1_405b_with_retry(standard_prompt)
|
694 |
+
meta_llama_405b_length = len(meta_llama_405b_message)
|
695 |
+
return f"{meta_llama_405b_message}\n\n------\nКоличество знаков: {meta_llama_405b_length}"
|
696 |
+
|
697 |
+
def personalize_message_gpt4o(gpt4o_message, key_message, approach, *selected_values):
|
698 |
+
personalization_prompt = generate_personalization_prompt(key_message, approach, *selected_values)
|
699 |
+
personalized_message = perform_personalization(gpt4o_message, personalization_prompt)
|
700 |
+
gpt4o_length = len(personalized_message)
|
701 |
+
return f"{personalized_message}\n\n------\nКоличество знаков: {gpt4o_length}"
|
702 |
+
|
703 |
+
def personalize_message_gigachat_pro(gigachat_pro_message, key_message, approach, *selected_values):
|
704 |
+
personalization_prompt = generate_personalization_prompt(key_message, approach, *selected_values)
|
705 |
+
personalized_message = perform_personalization_gigachat(gigachat_pro_message, personalization_prompt, "gigachat_pro")
|
706 |
+
gigachat_pro_length = len(personalized_message)
|
707 |
+
return f"{personalized_message}\n\n------\nКоличество знаков: {gigachat_pro_length}"
|
708 |
+
|
709 |
+
def personalize_message_gigachat_lite(gigachat_lite_message, key_message, approach, *selected_values):
|
710 |
+
personalization_prompt = generate_personalization_prompt(key_message, approach, *selected_values)
|
711 |
+
personalized_message = perform_personalization_gigachat(gigachat_lite_message, personalization_prompt, "gigachat_lite")
|
712 |
+
gigachat_lite_length = len(personalized_message)
|
713 |
+
return f"{personalized_message}\n\n------\nКоличество знаков: {gigachat_lite_length}"
|
714 |
+
|
715 |
+
def personalize_message_gigachat_plus(gigachat_plus_message, key_message, approach, *selected_values):
|
716 |
+
personalization_prompt = generate_personalization_prompt(key_message, approach, *selected_values)
|
717 |
+
personalized_message = perform_personalization_gigachat(gigachat_plus_message, personalization_prompt, "gigachat_plus")
|
718 |
+
gigachat_plus_length = len(personalized_message)
|
719 |
+
return f"{personalized_message}\n\n------\nКоличество знаков: {gigachat_plus_length}"
|
720 |
+
|
721 |
+
def personalize_message_meta_llama_405b(meta_llama_405b_message, key_message, approach, *selected_values):
|
722 |
+
personalization_prompt = generate_personalization_prompt(key_message, approach, *selected_values)
|
723 |
+
personalized_message = perform_personalization_meta_llama_405b(meta_llama_405b_message, personalization_prompt)
|
724 |
+
meta_llama_405b_length = len(personalized_message)
|
725 |
+
return f"{personalized_message}\n\n------\nКоличество знаков: {meta_llama_405b_length}"
|
726 |
+
|
727 |
|
728 |
# Создание интерфейса Gradio
|
729 |
with gr.Blocks() as demo:
|
|
|
783 |
personalize_btn = gr.Button("2. Выполнить персонализацию (нажимать только после кнопки 1)", elem_id="personalize_button")
|
784 |
load_btn = gr.Button("Вернуть параметры предыдущего запроса")
|
785 |
|
786 |
+
# Ряд кнопок "Перегенерировать"
|
787 |
+
with gr.Row():
|
788 |
+
regen_gpt4o_btn = gr.Button("Перегенерировать GPT-4o")
|
789 |
+
regen_gigachat_pro_btn = gr.Button("Перегенерировать GigaChat-Pro")
|
790 |
+
regen_gigachat_lite_btn = gr.Button("Перегенерировать GigaChat-Lite")
|
791 |
+
regen_gigachat_plus_btn = gr.Button("Перегенерировать GigaChat-Plus")
|
792 |
+
regen_meta_llama_405b_btn = gr.Button("Перегенерировать Meta-Llama-3.1-405B")
|
793 |
+
|
794 |
# Первый ряд: неперсонализированные сообщения
|
795 |
with gr.Row():
|
796 |
output_text_gpt4o = gr.Textbox(label="Неперсонализированное сообщение GPT-4o", lines=3, interactive=False)
|
|
|
798 |
output_text_gigachat_lite = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Lite", lines=3, interactive=False)
|
799 |
output_text_gigachat_plus = gr.Textbox(label="Неперсонализированное сообщение GigaChat-Plus", lines=3, interactive=False)
|
800 |
output_text_meta_llama_405b = gr.Textbox(label="Неперсонализированное сообщение Meta-Llama-3.1-405B", lines=3, interactive=False)
|
801 |
+
|
802 |
+
# Ряд кнопок "Персонализировать"
|
803 |
+
with gr.Row():
|
804 |
+
personalize_gpt4o_btn = gr.Button("Персонализировать")
|
805 |
+
personalize_gigachat_pro_btn = gr.Button("Персонализировать")
|
806 |
+
personalize_gigachat_lite_btn = gr.Button("Персонализировать")
|
807 |
+
personalize_gigachat_plus_btn = gr.Button("Персонализировать")
|
808 |
+
personalize_meta_llama_405b_btn = gr.Button("Персонализировать")
|
809 |
|
810 |
# Второй ряд: персонализированные сообщения
|
811 |
with gr.Row():
|
|
|
963 |
]
|
964 |
)
|
965 |
|
966 |
+
regen_gpt4o_btn.click(
|
967 |
+
regen_message_gpt4o,
|
968 |
+
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
969 |
+
outputs=output_text_gpt4o
|
970 |
+
)
|
971 |
+
|
972 |
+
regen_gigachat_pro_btn.click(
|
973 |
+
regen_message_gigachat_pro,
|
974 |
+
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
975 |
+
outputs=output_text_gigachat_pro
|
976 |
+
)
|
977 |
+
|
978 |
+
regen_gigachat_lite_btn.click(
|
979 |
+
regen_message_gigachat_lite,
|
980 |
+
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
981 |
+
outputs=output_text_gigachat_lite
|
982 |
+
)
|
983 |
+
|
984 |
+
regen_gigachat_plus_btn.click(
|
985 |
+
regen_message_gigachat_plus,
|
986 |
+
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
987 |
+
outputs=output_text_gigachat_plus
|
988 |
+
)
|
989 |
+
|
990 |
+
regen_meta_llama_405b_btn.click(
|
991 |
+
regen_message_meta_llama_405b,
|
992 |
+
inputs=[description_input, advantages_input, key_message_input, approach_input] + selections,
|
993 |
+
outputs=output_text_meta_llama_405b
|
994 |
+
)
|
995 |
+
|
996 |
+
personalize_gpt4o_btn.click(
|
997 |
+
personalize_message_gpt4o,
|
998 |
+
inputs=[output_text_gpt4o, key_message_input, approach_input] + selections,
|
999 |
+
outputs=personalized_output_text_gpt4o
|
1000 |
+
)
|
1001 |
+
|
1002 |
+
personalize_gigachat_pro_btn.click(
|
1003 |
+
personalize_message_gigachat_pro,
|
1004 |
+
inputs=[output_text_gigachat_pro, key_message_input, approach_input] + selections,
|
1005 |
+
outputs=personalized_output_text_gigachat_pro
|
1006 |
+
)
|
1007 |
+
|
1008 |
+
personalize_gigachat_lite_btn.click(
|
1009 |
+
personalize_message_gigachat_lite,
|
1010 |
+
inputs=[output_text_gigachat_lite, key_message_input, approach_input] + selections,
|
1011 |
+
outputs=personalized_output_text_gigachat_lite
|
1012 |
+
)
|
1013 |
+
|
1014 |
+
personalize_gigachat_plus_btn.click(
|
1015 |
+
personalize_message_gigachat_plus,
|
1016 |
+
inputs=[output_text_gigachat_plus, key_message_input, approach_input] + selections,
|
1017 |
+
outputs=personalized_output_text_gigachat_plus
|
1018 |
+
)
|
1019 |
+
|
1020 |
+
personalize_meta_llama_405b_btn.click(
|
1021 |
+
personalize_message_meta_llama_405b,
|
1022 |
+
inputs=[output_text_meta_llama_405b, key_message_input, approach_input] + selections,
|
1023 |
+
outputs=personalized_output_text_meta_llama_405b
|
1024 |
+
)
|
1025 |
|
1026 |
# Привязка кнопок к функциям сохранения
|
1027 |
save_gpt4o_btn.click(
|