Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -301,41 +301,43 @@ def check_errors_with_yield(*personalized_messages):
|
|
301 |
yield error_check_prompt, error_message_gpt4o, error_message_gigachat_pro, error_message_gigachat_lite, error_message_gigachat_plus, "Все результаты проверки сгенерированы"
|
302 |
|
303 |
|
304 |
-
def save_to_github(
|
305 |
-
#
|
306 |
-
|
307 |
-
file_name = f"file_{timestamp}.json"
|
308 |
-
|
309 |
-
# Данные для записи
|
310 |
-
file_content = {
|
311 |
"Модель": model_name,
|
312 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
}
|
314 |
|
315 |
# Преобразуем контент в JSON-строку и кодируем в base64
|
316 |
-
file_content_encoded = base64.b64encode(json.dumps(
|
317 |
|
318 |
# Параметры для GitHub API
|
319 |
repo = "fruitpicker01/Storage_1"
|
320 |
-
path =
|
321 |
url = f"https://api.github.com/repos/{repo}/contents/{path}"
|
322 |
headers = {
|
323 |
"Authorization": f"token {token}",
|
324 |
"Content-Type": "application/json"
|
325 |
}
|
326 |
data = {
|
327 |
-
"message": f"Добавлен новый файл {
|
328 |
"content": file_content_encoded
|
329 |
}
|
330 |
|
331 |
# Отправка POST-запроса на GitHub API для создания файла в репозитории
|
332 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
333 |
-
|
334 |
-
if response.status_code == 201:
|
335 |
-
print(f"Файл {file_name} успешно добавлен в репозиторий.")
|
336 |
-
else:
|
337 |
-
print(f"Ошибка при добавлении файла: {response.status_code}")
|
338 |
-
print(response.json())
|
339 |
|
340 |
|
341 |
# Создание интерфейса Gradio
|
@@ -427,11 +429,89 @@ with gr.Blocks() as demo:
|
|
427 |
save_gigachat_plus_btn = gr.Button("👍")
|
428 |
|
429 |
# Привязка кнопок к функциям сохранения
|
430 |
-
save_gpt4o_btn.click(
|
431 |
-
|
432 |
-
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
|
436 |
# Использование сохраненных переменных в следующем блоке
|
437 |
with gr.Row():
|
|
|
301 |
yield error_check_prompt, error_message_gpt4o, error_message_gigachat_pro, error_message_gigachat_lite, error_message_gigachat_plus, "Все результаты проверки сгенерированы"
|
302 |
|
303 |
|
304 |
+
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):
|
305 |
+
# Собираем все данные в один словарь
|
306 |
+
data_to_save = {
|
|
|
|
|
|
|
|
|
307 |
"Модель": model_name,
|
308 |
+
"Персонализированное сообщение": personalized_message,
|
309 |
+
"Комментарий": comment,
|
310 |
+
"Откорректированное сообщение": corrected_message,
|
311 |
+
"Описание предложения": description,
|
312 |
+
"Преимущества": advantages,
|
313 |
+
"Неперсонализированный промпт": non_personalized_prompt,
|
314 |
+
"Неперсонализированное сообщение": non_personalized_message,
|
315 |
+
"Пол": gender,
|
316 |
+
"Поколение": generation,
|
317 |
+
"Психотип": psychotype,
|
318 |
+
"Стадия бизнеса": business_stage,
|
319 |
+
"Отрасль": industry,
|
320 |
+
"ОПФ": legal_form
|
321 |
}
|
322 |
|
323 |
# Преобразуем контент в JSON-строку и кодируем в base64
|
324 |
+
file_content_encoded = base64.b64encode(json.dumps(data_to_save).encode()).decode()
|
325 |
|
326 |
# Параметры для GitHub API
|
327 |
repo = "fruitpicker01/Storage_1"
|
328 |
+
path = f"file_{int(time.time())}.json"
|
329 |
url = f"https://api.github.com/repos/{repo}/contents/{path}"
|
330 |
headers = {
|
331 |
"Authorization": f"token {token}",
|
332 |
"Content-Type": "application/json"
|
333 |
}
|
334 |
data = {
|
335 |
+
"message": f"Добавлен новый файл {path}",
|
336 |
"content": file_content_encoded
|
337 |
}
|
338 |
|
339 |
# Отправка POST-запроса на GitHub API для создания файла в репозитории
|
340 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
|
342 |
|
343 |
# Создание интерфейса Gradio
|
|
|
429 |
save_gigachat_plus_btn = gr.Button("👍")
|
430 |
|
431 |
# Привязка кнопок к функциям сохранения
|
432 |
+
save_gpt4o_btn.click(
|
433 |
+
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form:
|
434 |
+
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),
|
435 |
+
inputs=[
|
436 |
+
personalized_output_text_gpt4o,
|
437 |
+
comment_gpt4o,
|
438 |
+
corrected_gpt4o,
|
439 |
+
description_input,
|
440 |
+
advantages_input,
|
441 |
+
prompt_display,
|
442 |
+
output_text_gpt4o,
|
443 |
+
selections[0], # Пол
|
444 |
+
selections[1], # Поколение
|
445 |
+
selections[2], # Психотип
|
446 |
+
selections[3], # Стадия бизнеса
|
447 |
+
selections[4], # Отрасль
|
448 |
+
selections[5] # ОПФ
|
449 |
+
],
|
450 |
+
outputs=None
|
451 |
+
)
|
452 |
+
|
453 |
+
save_gigachat_pro_btn.click(
|
454 |
+
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form:
|
455 |
+
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),
|
456 |
+
inputs=[
|
457 |
+
personalized_output_text_gigachat_pro,
|
458 |
+
comment_gigachat_pro,
|
459 |
+
corrected_gigachat_pro,
|
460 |
+
description_input,
|
461 |
+
advantages_input,
|
462 |
+
prompt_display,
|
463 |
+
output_text_gigachat_pro,
|
464 |
+
selections[0], # Пол
|
465 |
+
selections[1], # Поколение
|
466 |
+
selections[2], # Психотип
|
467 |
+
selections[3], # Стадия бизнеса
|
468 |
+
selections[4], # Отрасль
|
469 |
+
selections[5] # ОПФ
|
470 |
+
],
|
471 |
+
outputs=None
|
472 |
+
)
|
473 |
+
|
474 |
+
save_gigachat_lite_btn.click(
|
475 |
+
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form:
|
476 |
+
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),
|
477 |
+
inputs=[
|
478 |
+
personalized_output_text_gigachat_lite,
|
479 |
+
comment_gigachat_lite,
|
480 |
+
corrected_gigachat_lite,
|
481 |
+
description_input,
|
482 |
+
advantages_input,
|
483 |
+
prompt_display,
|
484 |
+
output_text_gigachat_lite,
|
485 |
+
selections[0], # Пол
|
486 |
+
selections[1], # Поколение
|
487 |
+
selections[2], # Психотип
|
488 |
+
selections[3], # Стадия бизнеса
|
489 |
+
selections[4], # Отрасль
|
490 |
+
selections[5] # ОПФ
|
491 |
+
],
|
492 |
+
outputs=None
|
493 |
+
)
|
494 |
|
495 |
+
save_gigachat_plus_btn.click(
|
496 |
+
fn=lambda personalized_message, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form:
|
497 |
+
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),
|
498 |
+
inputs=[
|
499 |
+
personalized_output_text_gigachat_plus,
|
500 |
+
comment_gigachat_plus,
|
501 |
+
corrected_gigachat_plus,
|
502 |
+
description_input,
|
503 |
+
advantages_input,
|
504 |
+
prompt_display,
|
505 |
+
output_text_gigachat_plus,
|
506 |
+
selections[0], # Пол
|
507 |
+
selections[1], # Поколение
|
508 |
+
selections[2], # Психотип
|
509 |
+
selections[3], # Стадия бизнеса
|
510 |
+
selections[4], # Отрасль
|
511 |
+
selections[5] # ОПФ
|
512 |
+
],
|
513 |
+
outputs=None
|
514 |
+
)
|
515 |
|
516 |
# Использование сохраненных переменных в следующем блоке
|
517 |
with gr.Row():
|