Wajahat698 commited on
Commit
7d95fad
·
verified ·
1 Parent(s): a8a9c22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -144,6 +144,7 @@ def send_feedback_via_email(name, email, feedback):
144
  except Exception as e:
145
  st.error(f"Error sending email: {e}")
146
 
 
147
  def clean_text(text):
148
  # Use BeautifulSoup to parse and clean HTML
149
  soup = BeautifulSoup(text, 'html.parser')
@@ -152,10 +153,17 @@ def clean_text(text):
152
  for a in soup.find_all('a'):
153
  a.replace_with(f"[{a.get_text()}]({a['href']})")
154
 
155
- # Remove unwanted tags but preserve their text
156
- for tag in ['span', 'i', 'b', 'u', 'em', 'strong']:
157
  for element in soup.find_all(tag):
158
  element.unwrap() # Remove the tag but keep the content
 
 
 
 
 
 
 
159
 
160
  # Get the cleaned text
161
  cleaned_text = soup.get_text()
@@ -602,7 +610,8 @@ if prompt :
602
  st.write(full_response)
603
 
604
  # Add AI response to chat history
605
- st.session_state.chat_history.append({"role": "assistant", "content": cleaned_text})
 
606
  copy_to_clipboard(full_response)
607
 
608
 
 
144
  except Exception as e:
145
  st.error(f"Error sending email: {e}")
146
 
147
+
148
  def clean_text(text):
149
  # Use BeautifulSoup to parse and clean HTML
150
  soup = BeautifulSoup(text, 'html.parser')
 
153
  for a in soup.find_all('a'):
154
  a.replace_with(f"[{a.get_text()}]({a['href']})")
155
 
156
+ # Remove <i> and <em> tags but keep their content
157
+ for tag in ['i', 'em']:
158
  for element in soup.find_all(tag):
159
  element.unwrap() # Remove the tag but keep the content
160
+
161
+ # Convert <b> and <strong> tags to Markdown bold
162
+ for tag in ['b', 'strong']:
163
+ for element in soup.find_all(tag):
164
+ element.insert_before('**')
165
+ element.insert_after('**')
166
+ element.unwrap()
167
 
168
  # Get the cleaned text
169
  cleaned_text = soup.get_text()
 
610
  st.write(full_response)
611
 
612
  # Add AI response to chat history
613
+ cleaned_response = clean_text(full_response)
614
+ st.session_state.chat_history.append({"role": "assistant", "content": cleaned_response})
615
  copy_to_clipboard(full_response)
616
 
617