HarshSanghavi commited on
Commit
f33ea38
1 Parent(s): d7762a9

Upload 2 files

Browse files
Files changed (1) hide show
  1. templates/chatwidget.html +79 -3
templates/chatwidget.html CHANGED
@@ -548,8 +548,20 @@
548
  justify-content: center;
549
  align-items: center;
550
  }
 
 
 
 
 
 
 
 
 
551
  </style>
552
-
 
 
 
553
  <div class="marwadi">
554
  Welcome To AI bestie
555
  </div>
@@ -595,9 +607,10 @@
595
  <script
596
  src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/4.0.2/bootstrap-material-design.css"></script>
597
  <script id="rendered-js">
 
598
  function chatWidget(id, name, status) {
599
  $.ajax({
600
- url: "https://bacancydataprophets-bmoxi.hf.space/chatwidget",
601
  type: "POST",
602
  data: JSON.stringify({
603
  user_id: id,
@@ -686,6 +699,8 @@
686
  var input = document.getElementById("chat_input");
687
  var submitBtn = document.getElementById("submit");
688
  var cancelRequest = document.getElementById("cancel");
 
 
689
  $("#cancel").click(function (e) {
690
  input.disabled = false;
691
  e.preventDefault();
@@ -708,10 +723,11 @@
708
  input.value = "";
709
 
710
  $.ajax({
711
- url: "https://bacancydataprophets-bmoxi.hf.space/chatwidget",
712
  type: "POST",
713
  data: JSON.stringify({
714
  query: msg,
 
715
  // message: `${msg} | ${window.logged_in_user.airtable_record_id}`,
716
  }),
717
  headers: {
@@ -752,13 +768,73 @@
752
  $("#chat-circle").click(function () {
753
  $("#chat-circle").toggle("scale");
754
  $(".chat-box").toggle("scale");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
  });
756
 
757
  $(".chat-box-toggle").click(function () {
758
  $("#chat-circle").toggle("scale");
759
  $(".chat-box").toggle("scale");
 
760
  });
761
  });
 
762
  </script>
763
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
764
  </body>
 
548
  justify-content: center;
549
  align-items: center;
550
  }
551
+
552
+ .bestie {
553
+ margin: 1rem;
554
+ display: flex;
555
+ justify-content: center;
556
+ align-items: center;
557
+ text-align: center;
558
+ width: 100vw;
559
+ }
560
  </style>
561
+ <div class="bestie">
562
+ <label>User Id</label>&nbsp;&nbsp;&nbsp;
563
+ <input type="text" id="user_id" />
564
+ </div>
565
  <div class="marwadi">
566
  Welcome To AI bestie
567
  </div>
 
607
  <script
608
  src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/4.0.2/bootstrap-material-design.css"></script>
609
  <script id="rendered-js">
610
+
611
  function chatWidget(id, name, status) {
612
  $.ajax({
613
+ url: "/chatwidget",
614
  type: "POST",
615
  data: JSON.stringify({
616
  user_id: id,
 
699
  var input = document.getElementById("chat_input");
700
  var submitBtn = document.getElementById("submit");
701
  var cancelRequest = document.getElementById("cancel");
702
+
703
+ var userId = document.getElementById("user_id");
704
  $("#cancel").click(function (e) {
705
  input.disabled = false;
706
  e.preventDefault();
 
723
  input.value = "";
724
 
725
  $.ajax({
726
+ url: "/chatwidget",
727
  type: "POST",
728
  data: JSON.stringify({
729
  query: msg,
730
+ user_id: userId.value
731
  // message: `${msg} | ${window.logged_in_user.airtable_record_id}`,
732
  }),
733
  headers: {
 
768
  $("#chat-circle").click(function () {
769
  $("#chat-circle").toggle("scale");
770
  $(".chat-box").toggle("scale");
771
+ cancelRequest.style.display = 'block';
772
+ input.disabled = true;
773
+ $.ajax({
774
+ url: "/start-session",
775
+ type: "POST",
776
+ data: JSON.stringify({
777
+ user_id: userId.value
778
+ // message: `${msg} | ${window.logged_in_user.airtable_record_id}`,
779
+ }),
780
+ headers: {
781
+ "Content-Type": "application/json",
782
+ },
783
+ success: function (data) {
784
+
785
+ $.ajax({
786
+ url: "/chatwidget",
787
+ type: "POST",
788
+ data: JSON.stringify({
789
+ query: "you are starting the conversion, with your best friend. also you know about previous summary and mood summary",
790
+ user_id: userId.value
791
+ // message: `${msg} | ${window.logged_in_user.airtable_record_id}`,
792
+ }),
793
+ headers: {
794
+ "Content-Type": "application/json",
795
+ "Access-Control-Allow-Origin": "*",
796
+ "Access-Control-Allow-Headers": "Content-Type",
797
+ },
798
+
799
+ success: function (data) {
800
+ console.log(data)
801
+ /* data.map(item => generate_message(item.text, "user")) */
802
+ generate_message(data, "user");
803
+ /* generate_message(data.response, "user"); */
804
+ input.disabled = false;
805
+ submitBtn.disabled = false;
806
+ input.style.opacity = 1;
807
+ cancelRequest.style.display = 'none';
808
+ },
809
+ error: function (data) {
810
+ error_message(
811
+ "We are sorry. we can't proceess Your Request Please Try again after some times.",
812
+ "user"
813
+ );
814
+ input.disabled = false;
815
+ submitBtn.disabled = false;
816
+ input.style.opacity = 1;
817
+ cancelRequest.style.display = 'none';
818
+ },
819
+ });
820
+ if (status == "end") {
821
+
822
+ return true;
823
+ } else {
824
+ console.log(data.response, "session_id");
825
+ }
826
+ },
827
+ });
828
+ console.log(userId, userId.value)
829
  });
830
 
831
  $(".chat-box-toggle").click(function () {
832
  $("#chat-circle").toggle("scale");
833
  $(".chat-box").toggle("scale");
834
+ location.reload();
835
  });
836
  });
837
+
838
  </script>
839
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
840
  </body>