Wajahat698 commited on
Commit
743e21c
·
verified ·
1 Parent(s): 6d91132

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -24
app.py CHANGED
@@ -144,48 +144,45 @@ def send_feedback_via_email(name, email, feedback):
144
  except Exception as e:
145
  st.error(f"Error sending email: {e}")
146
 
147
-
148
  def clean_text(text):
149
  # Replace escaped newlines with actual newlines
150
  text = text.replace('\\n', '\n')
151
-
152
  # Convert <a> tags to Markdown links
153
  def convert_links(match):
154
  url = match.group(1)
155
  link_text = match.group(2)
156
  return f"[{link_text}]({url})"
157
-
158
  # Handle <a> tags to preserve clickable URLs in Markdown format
159
  text = re.sub(r'<a [^>]*href="([^"]+)"[^>]*>(.*?)</a>', convert_links, text)
160
 
161
- # Remove <span>, <i>, <b>, and other unwanted HTML tags
162
- text = re.sub(r'<span[^>]*>|</span>|<i[^>]*>|</i>|<b[^>]*>|</b>', '', text)
163
-
164
- # Remove any remaining HTML tags
 
 
 
 
165
  text = re.sub(r'<[^>]+>', '', text)
166
 
 
 
 
 
 
 
167
  # Split the text into paragraphs
168
  paragraphs = text.split('\n\n')
169
-
170
  cleaned_paragraphs = []
171
  for paragraph in paragraphs:
172
  lines = paragraph.split('\n')
173
  cleaned_lines = []
174
  for line in lines:
175
- # Preserve and correctly format headings or bold text
176
- if line.strip().startswith('**') and line.strip().endswith('**'):
177
- cleaned_line = line.strip()
178
- else:
179
- # Remove asterisks, special characters, and fix merged text
180
- cleaned_line = re.sub(r'\*|\−|\∗', '', line)
181
- cleaned_line = re.sub(r'([a-z])([A-Z])', r'\1 \2', cleaned_line)
182
-
183
- # Handle bullet points correctly
184
- if cleaned_line.strip().startswith('-'):
185
- cleaned_line = '\n' + cleaned_line.strip()
186
-
187
  # Remove extra spaces
188
- cleaned_line = re.sub(r'\s+', ' ', cleaned_line).strip()
189
  cleaned_lines.append(cleaned_line)
190
 
191
  # Join the lines within each paragraph
@@ -389,10 +386,10 @@ prompt_message = f"""
389
 
390
  **ANNUAL REPORT ARTICLE/Article GUIDELINES**:
391
 
392
- - If the task is to write an Latest annual report article or article , respond with 2-3 paragraphs(this should include words count given) no headings summarizing the key content.
393
  - Follow the summary with three sub-headings:
394
  1. Example Proof Points: Present relevant facts and figures.
395
- 2. Heuristics Used: It should be heuristics that are particularly important and effective in marketing.
396
  3. Creative Techniques Used: Explain any metaphor, juxtaposition, analogy, or other techniques employed.
397
  4. DO NOT mix proof points with heuristics in these sections.
398
  DO NOT count these 3 sub-heading words in article that will be extra words with the article.
@@ -603,7 +600,7 @@ if prompt :
603
  try:
604
  # Generate response using the agent executor
605
  output = agent_executor.invoke({
606
- "input": f"{prompt} Always Be specific with numbers, dates, people, and $dollar amounts( Do Mention them) provide Latest information . Always Be specific and provide bold point examples and also Embed source links directly next to each point. All outputs should be in structured format. ",
607
 
608
  "chat_history": st.session_state.chat_history
609
  })
 
144
  except Exception as e:
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
+ # Preserve and correctly format headings (e.g., **Heading**)
161
+ def preserve_headings(match):
162
+ content = match.group(2)
163
+ return f"**{content.strip()}**"
164
+
165
+ text = re.sub(r'(<h[1-6][^>]*>)(.*?)(</h[1-6]>)', preserve_headings, text)
166
+
167
+ # Remove all other HTML tags including <span>, <p>, <b>, <i>, etc.
168
  text = re.sub(r'<[^>]+>', '', text)
169
 
170
+ # Clean up any redundant asterisks or special characters
171
+ text = re.sub(r'\*|\−|\∗', '', text)
172
+
173
+ # Fix merged words by adding a space between camel case words
174
+ text = re.sub(r'([a-z])([A-Z])', r'\1 \2', text)
175
+
176
  # Split the text into paragraphs
177
  paragraphs = text.split('\n\n')
178
+
179
  cleaned_paragraphs = []
180
  for paragraph in paragraphs:
181
  lines = paragraph.split('\n')
182
  cleaned_lines = []
183
  for line in lines:
 
 
 
 
 
 
 
 
 
 
 
 
184
  # Remove extra spaces
185
+ cleaned_line = re.sub(r'\s+', ' ', line).strip()
186
  cleaned_lines.append(cleaned_line)
187
 
188
  # Join the lines within each paragraph
 
386
 
387
  **ANNUAL REPORT ARTICLE/Article GUIDELINES**:
388
 
389
+ - If the task is to write an Latest year annual report article or article , respond with 2-3 paragraphs(this should include words count given) no headings summarizing the key content.
390
  - Follow the summary with three sub-headings:
391
  1. Example Proof Points: Present relevant facts and figures.
392
+ 2. Heuristics Used: Only Mention heuristics that are particularly important and effective in marketing.
393
  3. Creative Techniques Used: Explain any metaphor, juxtaposition, analogy, or other techniques employed.
394
  4. DO NOT mix proof points with heuristics in these sections.
395
  DO NOT count these 3 sub-heading words in article that will be extra words with the article.
 
600
  try:
601
  # Generate response using the agent executor
602
  output = agent_executor.invoke({
603
+ "input": f"{prompt} Always Be specific with numbers, dates, people, and $dollar amounts( Do Mention them) provide Latest information . Always Be specific and provide bold point examples and also Embed source links directly next to each point. All outputs should be in structured format.Remove itallic and span tags ",
604
 
605
  "chat_history": st.session_state.chat_history
606
  })