Spaces:
Paused
Paused
Update app.py
Browse files156 unmodified lines157158159160161162163372 unmodified lines536537538539540541542543544545546547548549550551156 unmodified linesst.error(f"Error saving feedback to Excel: {e}")def side():with st.sidebar.form(key='feedback_form'):372 unmodified lines})full_response = output["output"]text = re.sub(r'\s+', ' ', full_response) # Replace multiple spaces or newlines with a single spacetext = re.sub(r'([a-z])(\d)', r'\1 \2', full_response)text = re.sub(r'</span>', '', full_response) # Remove closing </span> tags# Display the responseif "**Trust Tip**" not in full_response and "**Suggestion**" not in full_response:trust_tip = random.choice(trust_tips)suggestion = random.choice(suggestions)text += f"\n\n**Trust Tip**: {trust_tip} \n\n **Suggestion**: {suggestion}"st.markdown(text, unsafe_allow_html=True)156 unmodified lines157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207372 unmodified lines580581582583584585586587588589590591592593594156 unmodified linesst.error(f"Error saving feedback to Excel: {e}")def clean_text(text):# Replace escaped newlines with actual newlinestext = text.replace('\\n', '\n')# Remove any span and italic tagstext = re.sub(r'<span[^>]*>', '', text)text = re.sub(r'</span>', '', text)text = re.sub(r'<i[^>]*>', '', text)text = re.sub(r'</i>', '', text)# Preserve and correctly format markdown linkstext = re.sub(r'\[([^\]]+)\]\((https?://[^\)]+)\)', r'\1: \2', text)# Split the text into paragraphsparagraphs = text.split('\n\n')cleaned_paragraphs = []for paragraph in paragraphs:lines = paragraph.split('\n')cleaned_lines = []for line in lines:# Preserve bold formatting for headingsif line.strip().startswith('**') and line.strip().endswith('**'):cleaned_line = line.strip()else:# Remove asterisks, special characters, and fix merged textcleaned_line = re.sub(r'\*|\−|\∗', '', line)cleaned_line = re.sub(r'([a-z])([A-Z])', r'\1 \2', cleaned_line)# Handle bullet pointsif cleaned_line.strip().startswith('-'):cleaned_line = '\n' + cleaned_line.strip()# Remove extra spacescleaned_line = re.sub(r'\s+', ' ', cleaned_line).strip()cleaned_lines.append(cleaned_line)# Join the lines within each paragraphcleaned_paragraph = '\n'.join(cleaned_lines)cleaned_paragraphs.append(cleaned_paragraph)# Join the paragraphs back togethercleaned_text = '\n\n'.join(para for para in cleaned_paragraphs if para)return cleaned_textdef side():with st.sidebar.form(key='feedback_form'):372 unmodified lines})full_response = output["output"]cleaned_text = clean_text(full_response)# Display the responseif "**Trust Tip**" not in full_response and "**Suggestion**" not in cleaned_text:trust_tip = random.choice(trust_tips)suggestion = random.choice(suggestions)cleaned_text += f"\n\n**Trust Tip**: {trust_tip} \n\n **Suggestion**: {suggestion}"st.write(cleaned_text, unsafe_allow_html=True)
app.py+50-7