Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,7 @@ from together import Together
|
|
12 |
import pymorphy2
|
13 |
import re
|
14 |
import string
|
|
|
15 |
|
16 |
morph = pymorphy2.MorphAnalyzer()
|
17 |
|
@@ -109,6 +110,70 @@ def save_user_request_to_github(description, advantages, key_message, approach,
|
|
109 |
else:
|
110 |
print(f"Ошибка при сохранении данных на GitHub: {response.status_code} {response.text}")
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
def load_previous_user_request_from_github():
|
113 |
global current_request_index # Используем глобальную переменную
|
114 |
|
@@ -160,6 +225,129 @@ def load_previous_user_request_from_github():
|
|
160 |
return "", "", "", "", "", "", "", "", "", "", None, None, None, None, None, None
|
161 |
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
# Функция для генерации стандартного промпта
|
164 |
def generate_standard_prompt(description, advantages, key_message, approach, *selected_values):
|
165 |
|
@@ -564,20 +752,21 @@ def generate_error_check_prompt():
|
|
564 |
return prompt
|
565 |
|
566 |
|
567 |
-
def save_to_github(personalized_message, model_name, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form, key_message, approach):
|
568 |
# Собираем все данные в один словарь
|
569 |
data_to_save = {
|
570 |
"Модель": model_name,
|
|
|
571 |
"Персонализированное сообщение": personalized_message,
|
572 |
"Комментарий": comment,
|
573 |
"Откорректированное сообщение": corrected_message,
|
574 |
"Описание предложения": description,
|
575 |
"Преимущества": advantages,
|
576 |
-
"Ключевое сообщение": key_message,
|
577 |
-
"Подход": approach,
|
578 |
"Неперсонализированный промпт": non_personalized_prompt,
|
579 |
"Неперсонализированное сообщение": non_personalized_message,
|
580 |
-
"Персонализированный промпт": personalization_prompt,
|
581 |
"Пол": gender,
|
582 |
"Поколение": generation,
|
583 |
"Психотип": psychotype,
|
@@ -604,6 +793,10 @@ def save_to_github(personalized_message, model_name, comment, corrected_message,
|
|
604 |
|
605 |
# Отправка POST-запроса на GitHub API для создания файла в репозитории
|
606 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
|
|
|
|
|
|
|
|
607 |
|
608 |
|
609 |
def personalize_and_save(
|
@@ -1685,16 +1878,6 @@ with gr.Blocks() as demo:
|
|
1685 |
)
|
1686 |
|
1687 |
|
1688 |
-
# analyze_btn = gr.Button("Выполнить анализ персонализации (экспериментальная фича)")
|
1689 |
-
|
1690 |
-
# with gr.Row():
|
1691 |
-
# analysis_gigachat_pro = gr.Textbox(label="Анализ персонализации сообщения 1", lines=4, interactive=False)
|
1692 |
-
# analysis_gigachat_lite = gr.Textbox(label="Анализ персонализации сообщения 2", lines=4, interactive=False)
|
1693 |
-
# analysis_gigachat_plus = gr.Textbox(label="Анализ персонализации сообщения 3", lines=4, interactive=False)
|
1694 |
-
# analysis_gpt4o = gr.Textbox(label="Анализ персонализации сообщения 4", lines=4, interactive=False)
|
1695 |
-
# analysis_meta_llama_405b = gr.Textbox(label="Анализ персонализации сообщения 5", lines=4, interactive=False)
|
1696 |
-
|
1697 |
-
|
1698 |
# Добавление функционала для кнопок
|
1699 |
submit_btn.click(
|
1700 |
clear_fields,
|
@@ -1787,7 +1970,26 @@ with gr.Blocks() as demo:
|
|
1787 |
]
|
1788 |
)
|
1789 |
|
1790 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1791 |
# Обработка клика по кнопке восстановления
|
1792 |
load_btn.click(
|
1793 |
fn=lambda: load_previous_user_request_from_github(),
|
@@ -1950,9 +2152,14 @@ with gr.Blocks() as demo:
|
|
1950 |
inputs=[],
|
1951 |
outputs=[save_gigachat_pro_btn]
|
1952 |
).then(
|
1953 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
1954 |
-
|
|
|
|
|
|
|
|
|
1955 |
inputs=[
|
|
|
1956 |
personalized_output_text_gigachat_pro,
|
1957 |
comment_gigachat_pro,
|
1958 |
corrected_gigachat_pro,
|
@@ -1978,6 +2185,7 @@ with gr.Blocks() as demo:
|
|
1978 |
fn=reset_button_text,
|
1979 |
outputs=[save_gigachat_pro_btn]
|
1980 |
)
|
|
|
1981 |
|
1982 |
# Повторяем аналогично для других кнопок:
|
1983 |
save_gigachat_lite_btn.click(
|
@@ -1985,9 +2193,14 @@ with gr.Blocks() as demo:
|
|
1985 |
inputs=[],
|
1986 |
outputs=[save_gigachat_lite_btn]
|
1987 |
).then(
|
1988 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
1989 |
-
|
|
|
|
|
|
|
|
|
1990 |
inputs=[
|
|
|
1991 |
personalized_output_text_gigachat_lite,
|
1992 |
comment_gigachat_lite,
|
1993 |
corrected_gigachat_lite,
|
@@ -2020,9 +2233,14 @@ with gr.Blocks() as demo:
|
|
2020 |
inputs=[],
|
2021 |
outputs=[save_gigachat_plus_btn]
|
2022 |
).then(
|
2023 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
2024 |
-
|
|
|
|
|
|
|
|
|
2025 |
inputs=[
|
|
|
2026 |
personalized_output_text_gigachat_plus,
|
2027 |
comment_gigachat_plus,
|
2028 |
corrected_gigachat_plus,
|
@@ -2049,14 +2267,20 @@ with gr.Blocks() as demo:
|
|
2049 |
outputs=[save_gigachat_plus_btn]
|
2050 |
)
|
2051 |
|
|
|
2052 |
save_gpt4o_btn.click(
|
2053 |
-
fn=prepare_button_text,
|
2054 |
inputs=[],
|
2055 |
outputs=[save_gpt4o_btn]
|
2056 |
).then(
|
2057 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
2058 |
-
|
|
|
|
|
|
|
|
|
2059 |
inputs=[
|
|
|
2060 |
personalized_output_text_gpt4o,
|
2061 |
comment_gpt4o,
|
2062 |
corrected_gpt4o,
|
@@ -2076,21 +2300,27 @@ with gr.Blocks() as demo:
|
|
2076 |
],
|
2077 |
outputs=None
|
2078 |
).then(
|
2079 |
-
fn=update_button_text,
|
2080 |
outputs=[save_gpt4o_btn]
|
2081 |
).then(
|
2082 |
-
fn=reset_button_text,
|
2083 |
outputs=[save_gpt4o_btn]
|
2084 |
)
|
|
|
2085 |
|
2086 |
save_meta_llama_405b_btn.click(
|
2087 |
fn=prepare_button_text,
|
2088 |
inputs=[],
|
2089 |
outputs=[save_meta_llama_405b_btn]
|
2090 |
).then(
|
2091 |
-
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
2092 |
-
|
|
|
|
|
|
|
|
|
2093 |
inputs=[
|
|
|
2094 |
personalized_output_text_meta_llama_405b,
|
2095 |
comment_meta_llama_405b,
|
2096 |
corrected_meta_llama_405b,
|
@@ -2117,25 +2347,5 @@ with gr.Blocks() as demo:
|
|
2117 |
outputs=[save_meta_llama_405b_btn]
|
2118 |
)
|
2119 |
|
2120 |
-
# Обработчик нажатия кнопки
|
2121 |
-
# analyze_btn.click(
|
2122 |
-
# fn=perform_analysis_with_yield,
|
2123 |
-
# inputs=[
|
2124 |
-
# output_text_gigachat_pro,
|
2125 |
-
# output_text_gigachat_lite,
|
2126 |
-
# output_text_gigachat_plus,
|
2127 |
-
# output_text_gpt4o,
|
2128 |
-
# output_text_meta_llama_405b,
|
2129 |
-
# personalization_prompt
|
2130 |
-
# ],
|
2131 |
-
# outputs=[
|
2132 |
-
# analysis_gigachat_pro,
|
2133 |
-
# analysis_gigachat_lite,
|
2134 |
-
# analysis_gigachat_plus,
|
2135 |
-
# analysis_gpt4o,
|
2136 |
-
# analysis_meta_llama_405b
|
2137 |
-
# ]
|
2138 |
-
# )
|
2139 |
-
|
2140 |
|
2141 |
demo.launch()
|
|
|
12 |
import pymorphy2
|
13 |
import re
|
14 |
import string
|
15 |
+
import io
|
16 |
|
17 |
morph = pymorphy2.MorphAnalyzer()
|
18 |
|
|
|
110 |
else:
|
111 |
print(f"Ошибка при сохранении данных на GitHub: {response.status_code} {response.text}")
|
112 |
|
113 |
+
|
114 |
+
def save_message_to_table(data):
|
115 |
+
# data is a dictionary containing the message and personalization parameters
|
116 |
+
|
117 |
+
repo = "fruitpicker01/Storage_dev"
|
118 |
+
file_path = "messages.csv" # Use 'messages.xlsx' if you prefer Excel
|
119 |
+
|
120 |
+
# Get the file from the repository
|
121 |
+
url = f"https://api.github.com/repos/{repo}/contents/{file_path}"
|
122 |
+
headers = {
|
123 |
+
"Authorization": f"token {token}",
|
124 |
+
"Content-Type": "application/json"
|
125 |
+
}
|
126 |
+
|
127 |
+
response = requests.get(url, headers=headers)
|
128 |
+
|
129 |
+
if response.status_code == 200:
|
130 |
+
# File exists, download and load it
|
131 |
+
content = response.json()
|
132 |
+
file_content = base64.b64decode(content['content'])
|
133 |
+
if file_path.endswith('.xlsx'):
|
134 |
+
df = pd.read_excel(io.BytesIO(file_content))
|
135 |
+
else:
|
136 |
+
df = pd.read_csv(io.StringIO(file_content.decode('utf-8')))
|
137 |
+
sha = content['sha'] # For updating the file later
|
138 |
+
elif response.status_code == 404:
|
139 |
+
# File does not exist, create an empty DataFrame
|
140 |
+
df = pd.DataFrame(columns=[
|
141 |
+
"Timestamp", "Персонализированное сообщение", "Откорректированное сообщение",
|
142 |
+
"Пол", "Поколение", "Психотип", "Стадия бизнеса", "Отрасль", "ОПФ"
|
143 |
+
])
|
144 |
+
sha = None # No sha since the file doesn't exist yet
|
145 |
+
else:
|
146 |
+
print(f"Error accessing the file: {response.status_code}")
|
147 |
+
return
|
148 |
+
|
149 |
+
# Append the new data
|
150 |
+
df = df.append(data, ignore_index=True)
|
151 |
+
|
152 |
+
# Convert the DataFrame back to a file
|
153 |
+
if file_path.endswith('.xlsx'):
|
154 |
+
with io.BytesIO() as output:
|
155 |
+
df.to_excel(output, index=False)
|
156 |
+
file_content_encoded = base64.b64encode(output.getvalue()).decode('utf-8')
|
157 |
+
else:
|
158 |
+
csv_string = df.to_csv(index=False)
|
159 |
+
file_content_encoded = base64.b64encode(csv_string.encode('utf-8')).decode('utf-8')
|
160 |
+
|
161 |
+
# Prepare the data for the API request
|
162 |
+
data = {
|
163 |
+
"message": "Update messages file",
|
164 |
+
"content": file_content_encoded,
|
165 |
+
"sha": sha # Include the sha if the file exists
|
166 |
+
}
|
167 |
+
|
168 |
+
# Send the PUT request to update the file
|
169 |
+
response = requests.put(url, headers=headers, data=json.dumps(data))
|
170 |
+
|
171 |
+
if response.status_code in [200, 201]:
|
172 |
+
print("Messages file updated successfully.")
|
173 |
+
else:
|
174 |
+
print(f"Error updating messages file: {response.status_code}")
|
175 |
+
|
176 |
+
|
177 |
def load_previous_user_request_from_github():
|
178 |
global current_request_index # Используем глобальную переменную
|
179 |
|
|
|
225 |
return "", "", "", "", "", "", "", "", "", "", None, None, None, None, None, None
|
226 |
|
227 |
|
228 |
+
def get_reference_message(gender, generation, psychotype, business_stage, industry, legal_form):
|
229 |
+
# Import io if not already done
|
230 |
+
import io
|
231 |
+
|
232 |
+
# Define the repository and file path
|
233 |
+
repo = "fruitpicker01/Storage_dev"
|
234 |
+
file_path = "messages.csv" # Or 'messages.xlsx' if you prefer Excel
|
235 |
+
|
236 |
+
# Get the file from the repository
|
237 |
+
url = f"https://api.github.com/repos/{repo}/contents/{file_path}"
|
238 |
+
headers = {
|
239 |
+
"Authorization": f"token {token}",
|
240 |
+
"Content-Type": "application/json"
|
241 |
+
}
|
242 |
+
|
243 |
+
response = requests.get(url, headers=headers)
|
244 |
+
|
245 |
+
if response.status_code == 200:
|
246 |
+
# File exists, download and load it
|
247 |
+
content = response.json()
|
248 |
+
file_content = base64.b64decode(content['content'])
|
249 |
+
if file_path.endswith('.xlsx'):
|
250 |
+
df = pd.read_excel(io.BytesIO(file_content))
|
251 |
+
else:
|
252 |
+
df = pd.read_csv(io.StringIO(file_content.decode('utf-8')))
|
253 |
+
else:
|
254 |
+
# File does not exist or error
|
255 |
+
print(f"Error accessing the file: {response.status_code}")
|
256 |
+
return None
|
257 |
+
|
258 |
+
# Filter the DataFrame based on the personalization parameters
|
259 |
+
filter_condition = (
|
260 |
+
(df["Пол"] == gender) &
|
261 |
+
(df["Поколение"] == generation) &
|
262 |
+
(df["Психотип"] == psychotype) &
|
263 |
+
(df["Стадия бизнеса"] == business_stage) &
|
264 |
+
(df["Отрасль"] == industry) &
|
265 |
+
(df["ОПФ"] == legal_form)
|
266 |
+
)
|
267 |
+
|
268 |
+
filtered_df = df[filter_condition]
|
269 |
+
|
270 |
+
if filtered_df.empty:
|
271 |
+
# No previous messages with these parameters
|
272 |
+
return None
|
273 |
+
|
274 |
+
# Sort the filtered DataFrame by timestamp in descending order
|
275 |
+
filtered_df = filtered_df.sort_values(by="Timestamp", ascending=False)
|
276 |
+
|
277 |
+
# Get the latest message
|
278 |
+
latest_row = filtered_df.iloc[0]
|
279 |
+
|
280 |
+
# Get the "Откорректированное сообщение" if it exists, else "Персонализированное сообщение"
|
281 |
+
if pd.notnull(latest_row["Откорректированное сообщение"]) and latest_row["Откорректированное сообщение"].strip():
|
282 |
+
reference_message = latest_row["Откорректированное сообщение"]
|
283 |
+
else:
|
284 |
+
reference_message = latest_row["Персонализированное сообщение"]
|
285 |
+
|
286 |
+
return reference_message
|
287 |
+
|
288 |
+
def adapt_messages_to_best_example(
|
289 |
+
personalized_gigachat_pro,
|
290 |
+
personalized_gigachat_lite,
|
291 |
+
personalized_gigachat_plus,
|
292 |
+
personalized_gpt4o,
|
293 |
+
personalized_meta_llama_405b,
|
294 |
+
key_message,
|
295 |
+
approach,
|
296 |
+
*selected_values
|
297 |
+
):
|
298 |
+
# Extract personalization parameters
|
299 |
+
gender = selected_values[0]
|
300 |
+
generation = selected_values[1]
|
301 |
+
psychotype = selected_values[2]
|
302 |
+
business_stage = selected_values[3]
|
303 |
+
industry = selected_values[4]
|
304 |
+
legal_form = selected_values[5]
|
305 |
+
|
306 |
+
# Retrieve the reference message
|
307 |
+
reference_message = get_reference_message(gender, generation, psychotype, business_stage, industry, legal_form)
|
308 |
+
|
309 |
+
if not reference_message:
|
310 |
+
# No reference message found
|
311 |
+
adapted_messages = ["Эталонное сообщение не найдено для выбранных параметров персонализации."] * 5
|
312 |
+
return adapted_messages
|
313 |
+
else:
|
314 |
+
# Construct the prompt template
|
315 |
+
prompt_template = (
|
316 |
+
f"Есть эталонное сообщение: \"{reference_message}\". "
|
317 |
+
"Эталонное сообщение используется исключительно для адаптации стиля текста, а не для изменения его смысла. "
|
318 |
+
"Пожалуйста, следуй этой инструкции и сохраняй основной смысл исходного текста, адаптируя его под стилистику эталонного сообщения: \"{personalized_message}\"."
|
319 |
+
)
|
320 |
+
|
321 |
+
# Adapt each message
|
322 |
+
adapted_messages = []
|
323 |
+
# For GigaChat-Pro
|
324 |
+
prompt = prompt_template.format(personalized_message=personalized_gigachat_pro)
|
325 |
+
adapted_gigachat_pro = generate_message_gigachat_pro_with_retry(prompt)
|
326 |
+
adapted_messages.append(adapted_gigachat_pro)
|
327 |
+
|
328 |
+
# For GigaChat-Lite
|
329 |
+
prompt = prompt_template.format(personalized_message=personalized_gigachat_lite)
|
330 |
+
adapted_gigachat_lite = generate_message_gigachat_lite_with_retry(prompt)
|
331 |
+
adapted_messages.append(adapted_gigachat_lite)
|
332 |
+
|
333 |
+
# For GigaChat-Plus
|
334 |
+
prompt = prompt_template.format(personalized_message=personalized_gigachat_plus)
|
335 |
+
adapted_gigachat_plus = generate_message_gigachat_plus_with_retry(prompt)
|
336 |
+
adapted_messages.append(adapted_gigachat_plus)
|
337 |
+
|
338 |
+
# For GPT-4o
|
339 |
+
prompt = prompt_template.format(personalized_message=personalized_gpt4o)
|
340 |
+
adapted_gpt4o = generate_message_gpt4o_with_retry(prompt)
|
341 |
+
adapted_messages.append(adapted_gpt4o)
|
342 |
+
|
343 |
+
# For Meta-Llama-3.1-405B
|
344 |
+
prompt = prompt_template.format(personalized_message=personalized_meta_llama_405b)
|
345 |
+
adapted_meta_llama_405b = generate_message_meta_llama_3_1_405b_with_retry(prompt)
|
346 |
+
adapted_messages.append(adapted_meta_llama_405b)
|
347 |
+
|
348 |
+
return adapted_messages
|
349 |
+
|
350 |
+
|
351 |
# Функция для генерации стандартного промпта
|
352 |
def generate_standard_prompt(description, advantages, key_message, approach, *selected_values):
|
353 |
|
|
|
752 |
return prompt
|
753 |
|
754 |
|
755 |
+
def save_to_github(adapted_message, personalized_message, model_name, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form, key_message, approach):
|
756 |
# Собираем все данные в один словарь
|
757 |
data_to_save = {
|
758 |
"Модель": model_name,
|
759 |
+
"Адаптированное сообщение": adapted_message,
|
760 |
"Персонализированное сообщение": personalized_message,
|
761 |
"Комментарий": comment,
|
762 |
"Откорректированное сообщение": corrected_message,
|
763 |
"Описание предложения": description,
|
764 |
"Преимущества": advantages,
|
765 |
+
"Ключевое сообщение": key_message,
|
766 |
+
"Подход": approach,
|
767 |
"Неперсонализированный промпт": non_personalized_prompt,
|
768 |
"Неперсонализированное сообщение": non_personalized_message,
|
769 |
+
"Персонализированный промпт": personalization_prompt,
|
770 |
"Пол": gender,
|
771 |
"Поколение": generation,
|
772 |
"Психотип": psychotype,
|
|
|
793 |
|
794 |
# Отправка POST-запроса на GitHub API для создания файла в репозитории
|
795 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
796 |
+
if response.status_code == 201:
|
797 |
+
print("Данные успешно сохранены на GitHub")
|
798 |
+
else:
|
799 |
+
print(f"Ошибка при сохранении данных на GitHub: {response.status_code} {response.text}")
|
800 |
|
801 |
|
802 |
def personalize_and_save(
|
|
|
1878 |
)
|
1879 |
|
1880 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1881 |
# Добавление функционала для кнопок
|
1882 |
submit_btn.click(
|
1883 |
clear_fields,
|
|
|
1970 |
]
|
1971 |
)
|
1972 |
|
1973 |
+
best_example_btn.click(
|
1974 |
+
fn=adapt_messages_to_best_example,
|
1975 |
+
inputs=[
|
1976 |
+
personalized_output_text_gigachat_pro,
|
1977 |
+
personalized_output_text_gigachat_lite,
|
1978 |
+
personalized_output_text_gigachat_plus,
|
1979 |
+
personalized_output_text_gpt4o,
|
1980 |
+
personalized_output_text_meta_llama_405b,
|
1981 |
+
key_message_input,
|
1982 |
+
approach_input,
|
1983 |
+
] + selections,
|
1984 |
+
outputs=[
|
1985 |
+
adapted_output_text_gigachat_pro,
|
1986 |
+
adapted_output_text_gigachat_lite,
|
1987 |
+
adapted_output_text_gigachat_plus,
|
1988 |
+
adapted_output_text_gpt4o,
|
1989 |
+
adapted_output_text_meta_llama_405b,
|
1990 |
+
]
|
1991 |
+
)
|
1992 |
+
|
1993 |
# Обработка клика по кнопке восстановления
|
1994 |
load_btn.click(
|
1995 |
fn=lambda: load_previous_user_request_from_github(),
|
|
|
2152 |
inputs=[],
|
2153 |
outputs=[save_gigachat_pro_btn]
|
2154 |
).then(
|
2155 |
+
fn=lambda adapted_message, personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
2156 |
+
non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form,
|
2157 |
+
key_message, approach:
|
2158 |
+
save_to_github(adapted_message, personalized_message, "GigaChat-Pro", comment, corrected_message, description, advantages,
|
2159 |
+
non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype,
|
2160 |
+
business_stage, industry, legal_form, key_message, approach),
|
2161 |
inputs=[
|
2162 |
+
adapted_output_text_gigachat_pro,
|
2163 |
personalized_output_text_gigachat_pro,
|
2164 |
comment_gigachat_pro,
|
2165 |
corrected_gigachat_pro,
|
|
|
2185 |
fn=reset_button_text,
|
2186 |
outputs=[save_gigachat_pro_btn]
|
2187 |
)
|
2188 |
+
|
2189 |
|
2190 |
# Повторяем аналогично для других кнопок:
|
2191 |
save_gigachat_lite_btn.click(
|
|
|
2193 |
inputs=[],
|
2194 |
outputs=[save_gigachat_lite_btn]
|
2195 |
).then(
|
2196 |
+
fn=lambda adapted_message, personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
2197 |
+
non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form,
|
2198 |
+
key_message, approach:
|
2199 |
+
save_to_github(adapted_message, personalized_message, "GigaChat-Lite", comment, corrected_message, description, advantages,
|
2200 |
+
non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype,
|
2201 |
+
business_stage, industry, legal_form, key_message, approach),
|
2202 |
inputs=[
|
2203 |
+
adapted_output_text_gigachat_lite,
|
2204 |
personalized_output_text_gigachat_lite,
|
2205 |
comment_gigachat_lite,
|
2206 |
corrected_gigachat_lite,
|
|
|
2233 |
inputs=[],
|
2234 |
outputs=[save_gigachat_plus_btn]
|
2235 |
).then(
|
2236 |
+
fn=lambda adapted_message, personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
2237 |
+
non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form,
|
2238 |
+
key_message, approach:
|
2239 |
+
save_to_github(adapted_message, personalized_message, "GigaChat-Lite+", comment, corrected_message, description, advantages,
|
2240 |
+
non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype,
|
2241 |
+
business_stage, industry, legal_form, key_message, approach),
|
2242 |
inputs=[
|
2243 |
+
adapted_output_text_gigachat_plus,
|
2244 |
personalized_output_text_gigachat_plus,
|
2245 |
comment_gigachat_plus,
|
2246 |
corrected_gigachat_plus,
|
|
|
2267 |
outputs=[save_gigachat_plus_btn]
|
2268 |
)
|
2269 |
|
2270 |
+
|
2271 |
save_gpt4o_btn.click(
|
2272 |
+
fn=prepare_button_text,
|
2273 |
inputs=[],
|
2274 |
outputs=[save_gpt4o_btn]
|
2275 |
).then(
|
2276 |
+
fn=lambda adapted_message, personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
2277 |
+
non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form,
|
2278 |
+
key_message, approach:
|
2279 |
+
save_to_github(adapted_message, personalized_message, "GPT-4o", comment, corrected_message, description, advantages,
|
2280 |
+
non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype,
|
2281 |
+
business_stage, industry, legal_form, key_message, approach),
|
2282 |
inputs=[
|
2283 |
+
adapted_output_text_gpt4o,
|
2284 |
personalized_output_text_gpt4o,
|
2285 |
comment_gpt4o,
|
2286 |
corrected_gpt4o,
|
|
|
2300 |
],
|
2301 |
outputs=None
|
2302 |
).then(
|
2303 |
+
fn=update_button_text,
|
2304 |
outputs=[save_gpt4o_btn]
|
2305 |
).then(
|
2306 |
+
fn=reset_button_text,
|
2307 |
outputs=[save_gpt4o_btn]
|
2308 |
)
|
2309 |
+
|
2310 |
|
2311 |
save_meta_llama_405b_btn.click(
|
2312 |
fn=prepare_button_text,
|
2313 |
inputs=[],
|
2314 |
outputs=[save_meta_llama_405b_btn]
|
2315 |
).then(
|
2316 |
+
fn=lambda adapted_message, personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt,
|
2317 |
+
non_personalized_message, personalization_prompt, gender, generation, psychotype, business_stage, industry, legal_form,
|
2318 |
+
key_message, approach:
|
2319 |
+
save_to_github(adapted_message, personalized_message, "Meta-Llama-3.1-405B", comment, corrected_message, description, advantages,
|
2320 |
+
non_personalized_prompt, non_personalized_message, personalization_prompt, gender, generation, psychotype,
|
2321 |
+
business_stage, industry, legal_form, key_message, approach),
|
2322 |
inputs=[
|
2323 |
+
adapted_output_text_meta_llama_405b,
|
2324 |
personalized_output_text_meta_llama_405b,
|
2325 |
comment_meta_llama_405b,
|
2326 |
corrected_meta_llama_405b,
|
|
|
2347 |
outputs=[save_meta_llama_405b_btn]
|
2348 |
)
|
2349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2350 |
|
2351 |
demo.launch()
|