Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -515,6 +515,101 @@ def on_load_previous():
|
|
515 |
gender_val, generation_val, psychotype_val, business_stage_val, industry_val, opf_val,
|
516 |
chosen_approach_val, p1, p2, "", "", "")
|
517 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
with gr.Blocks(theme="default") as demo:
|
519 |
gr.Markdown("**Процент созданных SMS по выбранному продукту**")
|
520 |
progress_bar_html = """
|
|
|
515 |
gender_val, generation_val, psychotype_val, business_stage_val, industry_val, opf_val,
|
516 |
chosen_approach_val, p1, p2, "", "", "")
|
517 |
|
518 |
+
def save_preferred_sms_to_github(
|
519 |
+
selected_product, description, product_name, benefits, key_message,
|
520 |
+
gender, generation, psychotype, business_stage, industry, opf,
|
521 |
+
chosen_approach, presence_in_db,
|
522 |
+
model_1_name, prompt_1, sms_1,
|
523 |
+
model_2_name, prompt_2, sms_2,
|
524 |
+
chosen_sms
|
525 |
+
):
|
526 |
+
"""
|
527 |
+
Сохраняет выбранные поля в отдельный JSON-файл на GitHub,
|
528 |
+
чтобы не смешивать с предыдущими действиями, сохраняем под другим названием.
|
529 |
+
"""
|
530 |
+
# Собираем все данные
|
531 |
+
data_to_save = {
|
532 |
+
"timestamp": time.time(),
|
533 |
+
"product_dropdown": selected_product,
|
534 |
+
"description": description,
|
535 |
+
"product_name": product_name,
|
536 |
+
"benefits": benefits,
|
537 |
+
"key_message": key_message,
|
538 |
+
"gender": gender,
|
539 |
+
"generation": generation,
|
540 |
+
"psychotype": psychotype,
|
541 |
+
"business_stage": business_stage,
|
542 |
+
"industry": industry,
|
543 |
+
"opf": opf,
|
544 |
+
"chosen_approach": chosen_approach,
|
545 |
+
"comment": presence_in_db,
|
546 |
+
"model_1_name": model_1_name,
|
547 |
+
"prompt_1": prompt_1,
|
548 |
+
"sms_1": sms_1,
|
549 |
+
"model_2_name": model_2_name,
|
550 |
+
"prompt_2": prompt_2,
|
551 |
+
"sms_2": sms_2,
|
552 |
+
"preferred_sms": chosen_sms # "sms_1" или "sms_2"
|
553 |
+
}
|
554 |
+
|
555 |
+
file_content_encoded = base64.b64encode(json.dumps(data_to_save).encode()).decode()
|
556 |
+
filename = f"preferred_sms_{int(time.time())}.json"
|
557 |
+
url = f"https://api.github.com/repos/{repo}/contents/{filename}"
|
558 |
+
headers = {
|
559 |
+
"Authorization": f"token {token}",
|
560 |
+
"Content-Type": "application/json"
|
561 |
+
}
|
562 |
+
data = {
|
563 |
+
"message": f"Добавлен файл {filename} со сведениями о предпочтённом SMS",
|
564 |
+
"content": file_content_encoded
|
565 |
+
}
|
566 |
+
response = requests.put(url, headers=headers, data=json.dumps(data))
|
567 |
+
if response.status_code == 201:
|
568 |
+
print(f"Файл {filename} успешно сохранен.")
|
569 |
+
else:
|
570 |
+
print(f"Ошибка при сохранении данных: {response.status_code}, {response.text}")
|
571 |
+
|
572 |
+
def on_prefer_sms_1(
|
573 |
+
selected_product, description, product_name, benefits, key_message,
|
574 |
+
gender, generation, psychotype, business_stage, industry, opf,
|
575 |
+
chosen_approach, presence_in_db,
|
576 |
+
model_1_name, prompt_1, sms_1,
|
577 |
+
model_2_name, prompt_2, sms_2
|
578 |
+
):
|
579 |
+
"""
|
580 |
+
Вызывается при нажатии кнопки «Я предпочитаю это SMS» (для SMS 1).
|
581 |
+
"""
|
582 |
+
save_preferred_sms_to_github(
|
583 |
+
selected_product, description, product_name, benefits, key_message,
|
584 |
+
gender, generation, psychotype, business_stage, industry, opf,
|
585 |
+
chosen_approach, presence_in_db,
|
586 |
+
model_1_name, prompt_1, sms_1,
|
587 |
+
model_2_name, prompt_2, sms_2,
|
588 |
+
chosen_sms="sms_1"
|
589 |
+
)
|
590 |
+
return "Предпочтение SMS 1 сохранено в GitHub"
|
591 |
+
|
592 |
+
def on_prefer_sms_2(
|
593 |
+
selected_product, description, product_name, benefits, key_message,
|
594 |
+
gender, generation, psychotype, business_stage, industry, opf,
|
595 |
+
chosen_approach, presence_in_db,
|
596 |
+
model_1_name, prompt_1, sms_1,
|
597 |
+
model_2_name, prompt_2, sms_2
|
598 |
+
):
|
599 |
+
"""
|
600 |
+
Вызывается при нажатии кнопки «Я предпочитаю это SMS» (для SMS 2).
|
601 |
+
"""
|
602 |
+
save_preferred_sms_to_github(
|
603 |
+
selected_product, description, product_name, benefits, key_message,
|
604 |
+
gender, generation, psychotype, business_stage, industry, opf,
|
605 |
+
chosen_approach, presence_in_db,
|
606 |
+
model_1_name, prompt_1, sms_1,
|
607 |
+
model_2_name, prompt_2, sms_2,
|
608 |
+
chosen_sms="sms_2"
|
609 |
+
)
|
610 |
+
return "Предпочтение SMS 2 сохранено в GitHub"
|
611 |
+
|
612 |
+
|
613 |
with gr.Blocks(theme="default") as demo:
|
614 |
gr.Markdown("**Процент созданных SMS по выбранному продукту**")
|
615 |
progress_bar_html = """
|