Wajahat698 commited on
Commit
aecca20
·
verified ·
1 Parent(s): ec74958

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -151,13 +151,16 @@ def clean_text(text):
151
  text = text.replace('\\n', '\n')
152
 
153
  # Remove any span and italic tags
 
 
154
  text = re.sub(r'<span[^>]*>', '', text)
155
  text = re.sub(r'</span>', '', text)
156
  text = re.sub(r'<i[^>]*>', '', text)
157
  text = re.sub(r'</i>', '', text)
158
  text = re.sub(r'<span[^>]*>.*?</span>', '', text, flags=re.DOTALL)
159
  text = re.sub(r'<span[^>]*>.*?</span>', '', text, flags=re.DOTALL)
160
-
 
161
 
162
 
163
  # Preserve and correctly format markdown links (don't modify URLs)
@@ -195,7 +198,19 @@ def clean_text(text):
195
  cleaned_text = '\n\n'.join(para for para in cleaned_paragraphs if para)
196
 
197
  return cleaned_text
198
-
 
 
 
 
 
 
 
 
 
 
 
 
199
 
200
  def side():
201
  with st.sidebar.form(key='feedback_form'):
@@ -601,18 +616,13 @@ if prompt :
601
  cleaned_text = clean_text(full_response)
602
 
603
 
604
- cleaned_text = re.sub(r'</span>', '', cleaned_text)
605
- cleaned_text = re.sub(r'<span[^>]*>', '', cleaned_text)
606
  # Display the response
607
- if "**Trust Tip**" not in cleaned_text:
608
- trust_tip = random.choice(trust_tips)
609
- cleaned_text += f"\n\n**Trust Tip**: {trust_tip}"
610
-
611
- if "**Suggestion**" not in cleaned_text:
612
- suggestion = random.choice(suggestions)
613
- cleaned_text += f"\n\n**Suggestion**: {suggestion}"
614
 
615
- st.markdown(cleaned_text, unsafe_allow_html=True)
616
 
617
 
618
 
@@ -625,7 +635,7 @@ if prompt :
625
 
626
  # Add AI response to chat history
627
 
628
- st.session_state.chat_history.append({"role": "assistant", "content": cleaned_text})
629
  copy_to_clipboard(full_response)
630
 
631
 
 
151
  text = text.replace('\\n', '\n')
152
 
153
  # Remove any span and italic tags
154
+ text = re.sub(r'<[^>]+>', '', text)
155
+
156
  text = re.sub(r'<span[^>]*>', '', text)
157
  text = re.sub(r'</span>', '', text)
158
  text = re.sub(r'<i[^>]*>', '', text)
159
  text = re.sub(r'</i>', '', text)
160
  text = re.sub(r'<span[^>]*>.*?</span>', '', text, flags=re.DOTALL)
161
  text = re.sub(r'<span[^>]*>.*?</span>', '', text, flags=re.DOTALL)
162
+
163
+
164
 
165
 
166
  # Preserve and correctly format markdown links (don't modify URLs)
 
198
  cleaned_text = '\n\n'.join(para for para in cleaned_paragraphs if para)
199
 
200
  return cleaned_text
201
+
202
+ def add_trust_tip_and_suggestion(cleaned_text):
203
+ # Check if Trust Tip is already present
204
+ if "**Trust Tip**" not in cleaned_text:
205
+ trust_tip = random.choice(trust_tips)
206
+ cleaned_text += f"\n\n**Trust Tip**: {trust_tip}"
207
+
208
+ # Check if Suggestion is already present
209
+ if "**Suggestion**" not in cleaned_text:
210
+ suggestion = random.choice(suggestions)
211
+ cleaned_text += f"\n\n**Suggestion**: {suggestion}"
212
+
213
+ return cleaned_text
214
 
215
  def side():
216
  with st.sidebar.form(key='feedback_form'):
 
616
  cleaned_text = clean_text(full_response)
617
 
618
 
619
+ #cleaned_text = re.sub(r'</span>', '', cleaned_text)
620
+ #cleaned_text = re.sub(r'<span[^>]*>', '', cleaned_text)
621
  # Display the response
622
+ final_text = add_trust_tip_and_suggestion(cleaned_text)
623
+
 
 
 
 
 
624
 
625
+ st.markdown(final_text, unsafe_allow_html=True)
626
 
627
 
628
 
 
635
 
636
  # Add AI response to chat history
637
 
638
+ st.session_state.chat_history.append({"role": "assistant", "content": final_text})
639
  copy_to_clipboard(full_response)
640
 
641