Wajahat698 commited on
Commit
433b9a4
·
verified ·
1 Parent(s): 1d9752e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -56,7 +56,11 @@ st.markdown("""
56
  </style>
57
  """, unsafe_allow_html=True)
58
  if "chat_started" not in st.session_state:
59
- st.session_state["chat_started"] = False
 
 
 
 
60
  def copy_to_clipboard(text):
61
  """Creates a button to copy text to clipboard."""
62
  escaped_text = text.replace('\n', '\\n').replace('"', '\\"')
@@ -622,7 +626,12 @@ if prompt :
622
  #cleaned_text = re.sub(r'<span[^>]*>', '', cleaned_text)
623
  # Display the response
624
  trust_tip, suggestion = get_trust_tip_and_suggestion()
625
-
 
 
 
 
 
626
 
627
 
628
  combined_text = f"{cleaned_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
@@ -630,6 +639,10 @@ if prompt :
630
  #seprtor= st.markdown("---") # Add a separator
631
  #t_tip= st.markdown(f"**Trust Tip**: {trust_tip}")
632
  #s_sug- st.markdown(f"**Suggestion**: {suggestion}")
 
 
 
 
633
 
634
 
635
 
@@ -643,9 +656,6 @@ if prompt :
643
 
644
  # Add AI response to chat history
645
 
646
- if not st.session_state.chat_history or st.session_state.chat_history[-1]["content"] != combined_text:
647
- st.session_state.chat_history.append({"role": "assistant", "content": combined_text})
648
-
649
- copy_to_clipboard(full_response)
650
 
651
 
 
56
  </style>
57
  """, unsafe_allow_html=True)
58
  if "chat_started" not in st.session_state:
59
+ st.session_state["chat_started"] =
60
+ if 'previous_trust_tip' not in st.session_state:
61
+ st.session_state.previous_trust_tip = None
62
+ if 'previous_suggestion' not in st.session_state:
63
+ st.session_state.previous_suggestion = None
64
  def copy_to_clipboard(text):
65
  """Creates a button to copy text to clipboard."""
66
  escaped_text = text.replace('\n', '\\n').replace('"', '\\"')
 
626
  #cleaned_text = re.sub(r'<span[^>]*>', '', cleaned_text)
627
  # Display the response
628
  trust_tip, suggestion = get_trust_tip_and_suggestion()
629
+ if trust_tip == st.session_state.previous_trust_tip:
630
+ trust_tip = random.choice([t for t in trust_tips if t != st.session_state.previous_trust_tip])
631
+ if suggestion == st.session_state.previous_suggestion:
632
+ suggestion = random.choice([s for s in suggestions if s != st.session_state.previous_suggestion])
633
+ st.session_state.previous_trust_tip = trust_tip
634
+ st.session_state.previous_suggestion = suggestion
635
 
636
 
637
  combined_text = f"{cleaned_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
 
639
  #seprtor= st.markdown("---") # Add a separator
640
  #t_tip= st.markdown(f"**Trust Tip**: {trust_tip}")
641
  #s_sug- st.markdown(f"**Suggestion**: {suggestion}")
642
+ if not st.session_state.chat_history or st.session_state.chat_history[-1]["content"] != combined_text:
643
+ st.session_state.chat_history.append({"role": "assistant", "content": combined_text})
644
+
645
+ copy_to_clipboard(full_response)
646
 
647
 
648
 
 
656
 
657
  # Add AI response to chat history
658
 
659
+
 
 
 
660
 
661