Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -145,24 +145,55 @@ def send_feedback_via_email(name, email, feedback):
|
|
| 145 |
st.error(f"Error sending email: {e}")
|
| 146 |
|
| 147 |
def clean_text(text):
|
| 148 |
-
#
|
| 149 |
-
|
| 150 |
-
|
| 151 |
# Convert <a> tags to Markdown links
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
#
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
#
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
return cleaned_text
|
| 167 |
def side():
|
| 168 |
with st.sidebar.form(key='feedback_form'):
|
|
@@ -550,9 +581,9 @@ suggestions = [
|
|
| 550 |
]
|
| 551 |
|
| 552 |
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
|
| 557 |
st.session_state["chat_started"] = True
|
| 558 |
# Add user message to chat history
|
|
|
|
| 145 |
st.error(f"Error sending email: {e}")
|
| 146 |
|
| 147 |
def clean_text(text):
|
| 148 |
+
# Replace escaped newlines with actual newlines
|
| 149 |
+
text = text.replace('\\n', '\n')
|
| 150 |
+
|
| 151 |
# Convert <a> tags to Markdown links
|
| 152 |
+
def convert_links(match):
|
| 153 |
+
url = match.group(1)
|
| 154 |
+
link_text = match.group(2)
|
| 155 |
+
return f"[{link_text}]({url})"
|
| 156 |
+
|
| 157 |
+
# Handle <a> tags to preserve clickable URLs in Markdown format
|
| 158 |
+
text = re.sub(r'<a [^>]*href="([^"]+)"[^>]*>(.*?)</a>', convert_links, text)
|
| 159 |
+
|
| 160 |
+
# Remove <span>, <i>, <b>, and other unwanted HTML tags
|
| 161 |
+
text = re.sub(r'<span[^>]*>|</span>|<i[^>]*>|</i>|<b[^>]*>|</b>', '', text)
|
| 162 |
+
|
| 163 |
+
# Remove any remaining HTML tags
|
| 164 |
+
text = re.sub(r'<[^>]+>', '', text)
|
| 165 |
+
|
| 166 |
+
# Split the text into paragraphs
|
| 167 |
+
paragraphs = text.split('\n\n')
|
| 168 |
+
|
| 169 |
+
cleaned_paragraphs = []
|
| 170 |
+
for paragraph in paragraphs:
|
| 171 |
+
lines = paragraph.split('\n')
|
| 172 |
+
cleaned_lines = []
|
| 173 |
+
for line in lines:
|
| 174 |
+
# Preserve and correctly format headings or bold text
|
| 175 |
+
if line.strip().startswith('**') and line.strip().endswith('**'):
|
| 176 |
+
cleaned_line = line.strip()
|
| 177 |
+
else:
|
| 178 |
+
# Remove asterisks, special characters, and fix merged text
|
| 179 |
+
cleaned_line = re.sub(r'\*|\−|\∗', '', line)
|
| 180 |
+
cleaned_line = re.sub(r'([a-z])([A-Z])', r'\1 \2', cleaned_line)
|
| 181 |
+
|
| 182 |
+
# Handle bullet points correctly
|
| 183 |
+
if cleaned_line.strip().startswith('-'):
|
| 184 |
+
cleaned_line = '\n' + cleaned_line.strip()
|
| 185 |
+
|
| 186 |
+
# Remove extra spaces
|
| 187 |
+
cleaned_line = re.sub(r'\s+', ' ', cleaned_line).strip()
|
| 188 |
+
cleaned_lines.append(cleaned_line)
|
| 189 |
+
|
| 190 |
+
# Join the lines within each paragraph
|
| 191 |
+
cleaned_paragraph = '\n'.join(cleaned_lines)
|
| 192 |
+
cleaned_paragraphs.append(cleaned_paragraph)
|
| 193 |
+
|
| 194 |
+
# Join the paragraphs back together
|
| 195 |
+
cleaned_text = '\n\n'.join(para for para in cleaned_paragraphs if para)
|
| 196 |
+
|
| 197 |
return cleaned_text
|
| 198 |
def side():
|
| 199 |
with st.sidebar.form(key='feedback_form'):
|
|
|
|
| 581 |
]
|
| 582 |
|
| 583 |
|
| 584 |
+
|
| 585 |
+
prompt = st.chat_input("")
|
| 586 |
+
if prompt :
|
| 587 |
|
| 588 |
st.session_state["chat_started"] = True
|
| 589 |
# Add user message to chat history
|