fruitpicker01 commited on
Commit
215d6ed
·
verified ·
1 Parent(s): 99fbfbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +203 -1
app.py CHANGED
@@ -637,7 +637,157 @@ def on_prefer_sms_2(
637
  chosen_sms="sms_2"
638
  )
639
  return "Предпочтение SMS 2 сохранено в GitHub"
640
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
641
 
642
  with gr.Blocks(theme="default") as demo:
643
  gr.Markdown("**Процент созданных SMS по выбранному продукту**")
@@ -867,5 +1017,57 @@ with gr.Blocks(theme="default") as demo:
867
  outputs=[]
868
  )
869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
870
 
871
  demo.queue().launch()
 
637
  chosen_sms="sms_2"
638
  )
639
  return "Предпочтение SMS 2 сохранено в GitHub"
640
+
641
+ def save_sms_to_db(
642
+ selected_product,
643
+ description,
644
+ product_name,
645
+ benefits,
646
+ key_message,
647
+ gender,
648
+ generation,
649
+ psychotype,
650
+ business_stage,
651
+ industry,
652
+ opf,
653
+ chosen_approach,
654
+ presence_in_db,
655
+ model_name,
656
+ prompt_text,
657
+ final_prompt, # добавили финальный промпт
658
+ sms_text,
659
+ comment_sms,
660
+ corrected_sms
661
+ ):
662
+ data_to_save = {
663
+ "timestamp": time.time(),
664
+ "product_dropdown": selected_product,
665
+ "description": description,
666
+ "product_name": product_name,
667
+ "benefits": benefits,
668
+ "key_message": key_message,
669
+ "gender": gender,
670
+ "generation": generation,
671
+ "psychotype": psychotype,
672
+ "business_stage": business_stage,
673
+ "industry": industry,
674
+ "opf": opf,
675
+ "chosen_approach": chosen_approach,
676
+ "comment": presence_in_db,
677
+ "model": model_name,
678
+ "prompt": prompt_text,
679
+ "final_prompt": final_prompt, # сохраняем финальный промпт
680
+ "sms": sms_text,
681
+ "comment_sms": comment_sms,
682
+ "corrected_sms": corrected_sms
683
+ }
684
+
685
+ file_content_encoded = base64.b64encode(json.dumps(data_to_save).encode()).decode()
686
+ filename = f"saved_sms_{int(time.time())}.json"
687
+ url = f"https://api.github.com/repos/{repo}/contents/{filename}"
688
+ headers = {
689
+ "Authorization": f"token {token}",
690
+ "Content-Type": "application/json"
691
+ }
692
+ data = {
693
+ "message": f"Добавлен файл {filename} со сведениями о сохранённом SMS",
694
+ "content": file_content_encoded
695
+ }
696
+ resp = requests.put(url, headers=headers, data=json.dumps(data))
697
+ if resp.status_code == 201:
698
+ print(f"Файл {filename} успешно сохранён (save_sms_to_db).")
699
+ else:
700
+ print(f"Ошибка при сохранении (save_sms_to_db): {resp.status_code}, {resp.text}")
701
+
702
+ def on_save_sms_1(
703
+ selected_product,
704
+ description,
705
+ product_name,
706
+ benefits,
707
+ key_message,
708
+ gender,
709
+ generation,
710
+ psychotype,
711
+ business_stage,
712
+ industry,
713
+ opf,
714
+ chosen_approach,
715
+ presence_in_db,
716
+ model_1_name,
717
+ prompt_1,
718
+ final_prompt_1,
719
+ sms_1,
720
+ comment_sms_1,
721
+ corrected_sms_1
722
+ ):
723
+ save_sms_to_db(
724
+ selected_product=selected_product,
725
+ description=description,
726
+ product_name=product_name,
727
+ benefits=benefits,
728
+ key_message=key_message,
729
+ gender=gender,
730
+ generation=generation,
731
+ psychotype=psychotype,
732
+ business_stage=business_stage,
733
+ industry=industry,
734
+ opf=opf,
735
+ chosen_approach=chosen_approach,
736
+ presence_in_db=presence_in_db,
737
+ model_name=model_1_name,
738
+ prompt_text=prompt_1,
739
+ final_prompt=final_prompt_1,
740
+ sms_text=sms_1,
741
+ comment_sms=comment_sms_1,
742
+ corrected_sms=corrected_sms_1
743
+ )
744
+ return "SMS 1 сохранено в базу"
745
+
746
+
747
+ def on_save_sms_2(
748
+ selected_product,
749
+ description,
750
+ product_name,
751
+ benefits,
752
+ key_message,
753
+ gender,
754
+ generation,
755
+ psychotype,
756
+ business_stage,
757
+ industry,
758
+ opf,
759
+ chosen_approach,
760
+ presence_in_db,
761
+ model_2_name,
762
+ prompt_2,
763
+ final_prompt_2,
764
+ sms_2,
765
+ comment_sms_2,
766
+ corrected_sms_2
767
+ ):
768
+ save_sms_to_db(
769
+ selected_product=selected_product,
770
+ description=description,
771
+ product_name=product_name,
772
+ benefits=benefits,
773
+ key_message=key_message,
774
+ gender=gender,
775
+ generation=generation,
776
+ psychotype=psychotype,
777
+ business_stage=business_stage,
778
+ industry=industry,
779
+ opf=opf,
780
+ chosen_approach=chosen_approach,
781
+ presence_in_db=presence_in_db,
782
+ model_name=model_2_name,
783
+ prompt_text=prompt_2,
784
+ final_prompt=final_prompt_2,
785
+ sms_text=sms_2,
786
+ comment_sms=comment_sms_2,
787
+ corrected_sms=corrected_sms_2
788
+ )
789
+ return "SMS 2 сохранено в базу"
790
+
791
 
792
  with gr.Blocks(theme="default") as demo:
793
  gr.Markdown("**Процент созданных SMS по выбранному продукту**")
 
1017
  outputs=[]
1018
  )
1019
 
1020
+ save_sms_1_btn.click(
1021
+ fn=on_save_sms_1,
1022
+ inputs=[
1023
+ product_dropdown,
1024
+ description,
1025
+ product_name,
1026
+ benefits,
1027
+ key_message,
1028
+ gender_dropdown,
1029
+ generation_dropdown,
1030
+ psychotype_dropdown,
1031
+ business_stage_dropdown,
1032
+ industry_dropdown,
1033
+ opf_dropdown,
1034
+ chosen_approach,
1035
+ presence_in_db,
1036
+ model_1_name,
1037
+ prompt_1,
1038
+ final_prompt_1_state,
1039
+ sms_1,
1040
+ comment_sms_1,
1041
+ corrected_sms_1
1042
+ ],
1043
+ outputs=[]
1044
+ )
1045
+
1046
+ save_sms_2_btn.click(
1047
+ fn=on_save_sms_2,
1048
+ inputs=[
1049
+ product_dropdown,
1050
+ description,
1051
+ product_name,
1052
+ benefits,
1053
+ key_message,
1054
+ gender_dropdown,
1055
+ generation_dropdown,
1056
+ psychotype_dropdown,
1057
+ business_stage_dropdown,
1058
+ industry_dropdown,
1059
+ opf_dropdown,
1060
+ chosen_approach,
1061
+ presence_in_db,
1062
+ model_2_name,
1063
+ prompt_2,
1064
+ final_prompt_2_state,
1065
+ sms_2,
1066
+ comment_sms_2,
1067
+ corrected_sms_2
1068
+ ],
1069
+ outputs=[]
1070
+ )
1071
+
1072
 
1073
  demo.queue().launch()