Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -115,39 +115,37 @@ def generate_message_gigachat_plus(prompt):
|
|
115 |
except Exception as e:
|
116 |
return f"Ошибка при обращении к GigaChat-Lite+: {e}"
|
117 |
|
118 |
-
# Функция для обработки нажатия кнопки Submit и
|
119 |
def generate_messages(description, advantages, *selected_values):
|
120 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
121 |
|
122 |
results = {
|
123 |
"prompt": standard_prompt,
|
124 |
-
"gpt4o":
|
125 |
-
"gigachat_pro":
|
126 |
-
"gigachat_lite":
|
127 |
-
"gigachat_plus":
|
128 |
}
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
# Функция для выполнения персонализации
|
140 |
-
def
|
141 |
-
|
142 |
-
|
143 |
-
for i, feature in enumerate(features.keys()):
|
144 |
-
if selected_values[i]:
|
145 |
-
try:
|
146 |
-
personalized_texts.append(f"{features[feature][selected_values[i]]}")
|
147 |
-
except KeyError:
|
148 |
-
personalized_texts.append(f"Ошибка: выбранное значение {selected_values[i]} не найдено в данных.")
|
149 |
-
|
150 |
-
return personalized_texts
|
151 |
|
152 |
# Создание интерфейса Gradio
|
153 |
with gr.Blocks() as demo:
|
@@ -191,14 +189,12 @@ with gr.Blocks() as demo:
|
|
191 |
output_text_gigachat_pro = gr.Textbox(label="Создание сообщения GigaChat-Pro", lines=3)
|
192 |
output_text_gigachat_lite = gr.Textbox(label="Создание сообщения GigaChat-Lite", lines=3)
|
193 |
output_text_gigachat_plus = gr.Textbox(label="Создание сообщения GigaChat-Lite+", lines=3)
|
194 |
-
|
195 |
-
|
196 |
-
state = gr.State() # Переменная состояния для сохранения данных между функциями
|
197 |
|
198 |
submit_btn.click(
|
199 |
generate_messages,
|
200 |
inputs=[description_input, advantages_input] + selections,
|
201 |
-
outputs=[prompt_display, output_text_gpt4o, output_text_gigachat_pro, output_text_gigachat_lite, output_text_gigachat_plus,
|
202 |
)
|
203 |
|
204 |
with gr.Row():
|
@@ -206,9 +202,9 @@ with gr.Blocks() as demo:
|
|
206 |
|
207 |
with gr.Row():
|
208 |
personalize_btn.click(
|
209 |
-
|
210 |
-
inputs=
|
211 |
-
outputs=[gr.Textbox(label=
|
212 |
)
|
213 |
|
214 |
demo.launch()
|
|
|
115 |
except Exception as e:
|
116 |
return f"Ошибка при обращении к GigaChat-Lite+: {e}"
|
117 |
|
118 |
+
# Функция для обработки нажатия кнопки Submit и последовательного отображения результатов
|
119 |
def generate_messages(description, advantages, *selected_values):
|
120 |
standard_prompt = generate_standard_prompt(description, advantages, *selected_values)
|
121 |
|
122 |
results = {
|
123 |
"prompt": standard_prompt,
|
124 |
+
"gpt4o": None,
|
125 |
+
"gigachat_pro": None,
|
126 |
+
"gigachat_lite": None,
|
127 |
+
"gigachat_plus": None
|
128 |
}
|
129 |
|
130 |
+
yield results["prompt"], "", "", "", "", selected_values[0]
|
131 |
+
|
132 |
+
results["gpt4o"] = generate_message_gpt4o(standard_prompt)
|
133 |
+
yield results["prompt"], results["gpt4o"], "", "", "", selected_values[0]
|
134 |
+
|
135 |
+
results["gigachat_pro"] = generate_message_gigachat_pro(standard_prompt)
|
136 |
+
yield results["prompt"], results["gpt4o"], results["gigachat_pro"], "", "", selected_values[0]
|
137 |
+
|
138 |
+
results["gigachat_lite"] = generate_message_gigachat_lite(standard_prompt)
|
139 |
+
yield results["prompt"], results["gpt4o"], results["gigachat_pro"], results["gigachat_lite"], "", selected_values[0]
|
140 |
+
|
141 |
+
results["gigachat_plus"] = generate_message_gigachat_plus(standard_prompt)
|
142 |
+
yield results["prompt"], results["gpt4o"], results["gigachat_pro"], results["gigachat_lite"], results["gigachat_plus"], selected_values[0]
|
143 |
+
|
144 |
+
return results
|
145 |
|
146 |
# Функция для выполнения персонализации
|
147 |
+
def personalize_gender(selected_gender):
|
148 |
+
return f"Выбранный пол: {selected_gender}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
# Создание интерфейса Gradio
|
151 |
with gr.Blocks() as demo:
|
|
|
189 |
output_text_gigachat_pro = gr.Textbox(label="Создание сообщения GigaChat-Pro", lines=3)
|
190 |
output_text_gigachat_lite = gr.Textbox(label="Создание сообщения GigaChat-Lite", lines=3)
|
191 |
output_text_gigachat_plus = gr.Textbox(label="Создание сообщения GigaChat-Lite+", lines=3)
|
192 |
+
selected_gender_display = gr.Textbox(label="Выбранный пол", lines=1, interactive=False) # Блок для отображения выбранного пола
|
|
|
|
|
193 |
|
194 |
submit_btn.click(
|
195 |
generate_messages,
|
196 |
inputs=[description_input, advantages_input] + selections,
|
197 |
+
outputs=[prompt_display, output_text_gpt4o, output_text_gigachat_pro, output_text_gigachat_lite, output_text_gigachat_plus, selected_gender_display]
|
198 |
)
|
199 |
|
200 |
with gr.Row():
|
|
|
202 |
|
203 |
with gr.Row():
|
204 |
personalize_btn.click(
|
205 |
+
personalize_gender,
|
206 |
+
inputs=[selected_gender_display],
|
207 |
+
outputs=[gr.Textbox(label="Персонализированный результат", lines=3)]
|
208 |
)
|
209 |
|
210 |
demo.launch()
|