Wajahat698 commited on
Commit
2e0f6d4
·
verified ·
1 Parent(s): f5d346d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -40
app.py CHANGED
@@ -57,6 +57,16 @@ st.markdown("""
57
  """, unsafe_allow_html=True)
58
  if "chat_started" not in st.session_state:
59
  st.session_state["chat_started"] = False
 
 
 
 
 
 
 
 
 
 
60
  def copy_to_clipboard(text):
61
  """Creates a button to copy text to clipboard."""
62
  escaped_text = text.replace('\n', '\\n').replace('"', '\\"')
@@ -146,9 +156,10 @@ def send_feedback_via_email(name, email, feedback):
146
  st.error(f"Error sending email: {e}")
147
 
148
 
 
149
  def clean_text(text):
150
  text = text.replace('\\n', '\n')
151
-
152
  # Remove all HTML tags, including nested structures
153
  text = re.sub(r'<[^>]*>', '', text)
154
  # Remove any remaining < or > characters
@@ -189,15 +200,16 @@ def clean_text(text):
189
 
190
  # Join the paragraphs back together
191
  cleaned_text = '\n\n'.join(para for para in cleaned_paragraphs if para)
192
-
193
  return cleaned_text
 
194
 
195
 
 
 
196
  def get_trust_tip_and_suggestion():
197
  trust_tip = random.choice(trust_tips)
198
  suggestion = random.choice(suggestions)
199
  return trust_tip, suggestion
200
-
201
 
202
 
203
 
@@ -235,7 +247,7 @@ def side():
235
  <h3 class="competence">Competence Trust:</h3>
236
  <p>What competencies can I trust you for?</p>
237
  """, unsafe_allow_html=True)
238
- st.markdown("For detailed descriptions, visit [Academy](https://www.trustlogic.info/academy)")
239
 
240
 
241
 
@@ -297,6 +309,7 @@ def google_search(query):
297
  return ["Error occurred during Google search"]
298
 
299
 
 
300
  # RAG response function
301
  def rag_response(query):
302
  try:
@@ -335,64 +348,56 @@ prompt_message = f"""
335
  You are an expert copywriter specializing in creating high-quality marketing content that integrates TrustBuilders® into various content formats. Your goal is to produce compelling, factual, and well-structured material that adheres to the following guidelines and based on knowledge base:
336
  **GENERAL INSTRUCTIONS:**
337
  - **Consistency:** Maintain a uniform format across all content types.
338
- - **Tone:** Use an active, engaging, and direct tone. Avoid fluff, overly flowery language, or imaginative content without factual backing.
339
- - **Trademark Usage:** Only use the registered trademark symbol (®) with these brands: TrustLogic, TrustBuilder/TrustBuilders, Six Buckets of Trust, TrustifierAI. Do not use (®) with other brands.
340
  - **No Conclusions:** Do not include conclusions in your responses.
341
  - **Specificity:** Include relevant names, numbers like $dollars and years, programs, strategies, places, awards, actions.
342
- - **Sources:** Embed accurate source links directly after each factual statement or TrustBuilder® point except emails, newsletter etc contents.
343
  - **Formatting:** Avoid using HTML tags such as `<span>`, `<i>`, or others, except for the registered trademark symbol (®). Ensure that numerical values are properly formatted with spaces (e.g., 750 billion to 1 trillion). Do not use bold, italics, or other text styling for numbers.
344
- -**List of TrustBuilders® used :** Strictly return list of relevant trust builders used with facts and figures with embedded URL source links everytime.
345
-
346
  **CONTENT TYPES AND FORMATS:**
347
  1. **Annual Reports or Articles:**
348
  - Guidelines: Look in knowledge base for guiding principles for generation of marketing copy before generating response.
349
  - **Introduction:** Start with "Here is a draft of your [Annual Report/Article]. Feel free to suggest further refinements."
 
350
  - **Structure:**
351
  - **Headline:** This will contain the Principles.The headline should not mention TrustBuilders® or any trust buckets directly.
352
  - **Content:**
353
- - One main heading followed by 2-3 detailed paragraphs (according to word limit) summarizing key content (without source links included and without any headings).
354
  - **Perspective:** Write as if you are part of the organization (using "we"), emphasizing togetherness and collective effort.
355
  - **Sub-Headings (After Summary):**
356
  1. **List of TrustBuilders® used :** Strictly return list of relevant trust builders used with facts and figures with embedded URL source links everytime.
357
- 2. **Heuristics Used:** Include only key heuristics relevant to marketing (e.g., Social Proof, Scarcity).
358
  3. **Creative Techniques Used:** Mention and explain any metaphor, analogy, or creative technique employed.
359
- - **Word Count:** Main summary must meet the specified word count. Do not include the sub-heading sections in the word count limit.
360
-
361
-
362
-
363
-
364
  2. **Social Media Posts:**
365
  - **Format:** Create engaging posts with relevant hashtags.
366
  - **Intro Line:** Start with "Here is a draft of your social media post. Feel free to suggest further refinements."
367
  - **Content:** Ensure the post is concise, impactful, and designed to engage the audience.
368
  - **Additional Requirements:** Avoid mentioning trust buckets as hashtags or in the post copy. Ensure source links and trust builders are not included in the post text.
369
  - **List of TrustBuilders® used :** Provide a list of relevant TrustBuilders used with facts and figures and embedded URL source links.
370
-
371
  3. **Sales Conversations or Ad Copy:**
372
  - **Format:** Create a structured conversation or ad copy with clear messaging.
373
  - **Intro Line:** Start with "Here is a draft of your [Sales Conversation/Ad Copy]. Feel free to suggest further refinements."
374
  - **Content:** Include persuasive elements with integrated TrustBuilders®.
375
  - **List of TrustBuilders® used :** Provide a list of relevant TrustBuilders used with facts and figures and embedded URL source links.
376
-
377
 
378
  4. **Emails, Newsletters, Direct Marketing Letters:**
379
  - **Format:** Structure properly as an email or letter without any sub-headings.
380
  - **Intro Line:** Start with "Here is a draft of your [Email/Newsletter/Letter]. Feel free to suggest further refinements."
381
- - **Content:** Focus on clear, concise messaging with a call to action where appropriate.Do-not include source links here.
382
- - **Subject:** Give proper subject also for emails.
383
  - **Additional Requirements:** Ensure that trust builders are not mentioned in the email or letter body unless specifically required. Do-not include source links.
384
  - **Sub-Headings (At bottom):**
385
  1. **List of TrustBuilders® used :** Provide List of relevant trust builders used with facts and figures and with embedded source links.
386
- 2. **Heuristics Used:** Include only key heuristics relevant to marketing (e.g., Social Proof, Scarcity).
387
  3. **Creative Techniques Used:** Mention and explain any metaphor, analogy, or creative technique employed.
388
-
389
-
390
  5. **TRUST-BASED QUERIES:**
391
- - When a query specifically seeks proof points or content related to trust builders or trust buckets, follow these always guidelines:
392
  - **TrustBuilder® Integration:** Find and list a minimum of 15 Trust Builders points directly followed by relevant source links.
393
  - **Intro Line:** Start with "Here are some [Bucket name] TrustBuilders®. Let me know if you want to refine the results or find more."
394
- - **TrustBuilders® Format:** Categorise the TrustBuilders® correctly into the following key Headings:
395
-
396
  - ### Organization:** List details about the organization. do-not mention any heading within points.
397
  - ### People:** List individuals associated with the TrustBuilder®. do-not mention any heading within points.
398
  - ### Offers/Services:** Detail the offers or services provided. do-not mention any heading within points.
@@ -400,14 +405,12 @@ You are an expert copywriter specializing in creating high-quality marketing con
400
  - Write in bullet points under each heading.
401
  - Each point should not contain any sub-headings.
402
  - Give source links with each point.
 
403
  - No conclusions at the end of content unless specifically requested.
404
  - **Trust Bucket Focus:** Do not mix trust buckets; keep responses focused on the requested area.
405
  - *Refer to the knowledge base for Guiding Principles.*
406
-
407
  **GENERAL QUERIES:**
408
  - For general content like blogs or reports always refer knowledge base first, focus on the overall flow and structure without explicitly mentioning trust metrics unless requested.
409
-
410
-
411
  """
412
 
413
 
@@ -528,11 +531,11 @@ if not st.session_state.get("chat_started", False):
528
  <div class="section-container">
529
  <div class="section">
530
  <h2>Find</h2>
531
- <p>Discover all your great TrustBuilders®. <br> Example: Find Development Trust Builders® for Food for the Hungry
532
  </div>
533
  <div class="section">
534
  <h2>Create</h2>
535
- <p>Generate trust-optimised solutions : <br>Example: Find Food for the Hungry development TrustBuilders®. Then use them to write a 200-word annual report article. Enthusiastic tone.</p>
536
  </div>
537
  <div class="section">
538
  <h2>Trust-optimise</h2>
@@ -611,7 +614,7 @@ if prompt :
611
  try:
612
  # Generate response using the agent executor
613
  output = agent_executor.invoke({
614
- "input": f"{prompt} .Follow the guidelines please .Handle problematic text (Usually it is related to numbers, figures and text nearby )clean it up make spaced so that it is readable and properly formatted for display in a web application. Avoid any unusual line breaks or formatting issues. Always provide sources links with trust builders. Find right trust builders, do not mix please. ",
615
 
616
  "chat_history": st.session_state.chat_history
617
  })
@@ -621,16 +624,19 @@ if prompt :
621
  cleaned_text = clean_text(full_response)
622
  cleaned_text = re.sub(r'<[^>]*>', '', cleaned_text)
623
 
 
624
 
625
  #cleaned_text = re.sub(r'</span>', '', cleaned_text)
626
  #cleaned_text = re.sub(r'<span[^>]*>', '', cleaned_text)
627
  # Display the response
 
628
  trust_tip, suggestion = get_trust_tip_and_suggestion()
629
 
630
-
631
-
632
  combined_text = f"{cleaned_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
633
- st.markdown(combined_text, unsafe_allow_html=True)
 
 
634
  #seprtor= st.markdown("---") # Add a separator
635
  #t_tip= st.markdown(f"**Trust Tip**: {trust_tip}")
636
  #s_sug- st.markdown(f"**Suggestion**: {suggestion}")
@@ -645,9 +651,7 @@ if prompt :
645
  full_response = "I apologize, but an error occurred while generating the response. Please try again."
646
  st.write(full_response)
647
 
648
- # Add AI response to chat history
649
-
650
- st.session_state.chat_history.append({"role": "assistant", "content": combined_text})
651
- copy_to_clipboard(full_response)
652
-
653
 
 
 
 
57
  """, unsafe_allow_html=True)
58
  if "chat_started" not in st.session_state:
59
  st.session_state["chat_started"] = False
60
+ if 'previous_trust_tip' not in st.session_state:
61
+ st.session_state.previous_trust_tip = None
62
+ if 'previous_suggestion' not in st.session_state:
63
+ st.session_state.previous_suggestion = None
64
+
65
+ if 'used_trust_tips' not in st.session_state:
66
+ st.session_state.used_trust_tips = set()
67
+ if 'used_suggestions' not in st.session_state:
68
+ st.session_state.used_suggestions = set()
69
+
70
  def copy_to_clipboard(text):
71
  """Creates a button to copy text to clipboard."""
72
  escaped_text = text.replace('\n', '\\n').replace('"', '\\"')
 
156
  st.error(f"Error sending email: {e}")
157
 
158
 
159
+
160
  def clean_text(text):
161
  text = text.replace('\\n', '\n')
162
+
163
  # Remove all HTML tags, including nested structures
164
  text = re.sub(r'<[^>]*>', '', text)
165
  # Remove any remaining < or > characters
 
200
 
201
  # Join the paragraphs back together
202
  cleaned_text = '\n\n'.join(para for para in cleaned_paragraphs if para)
 
203
  return cleaned_text
204
+
205
 
206
 
207
+
208
+
209
  def get_trust_tip_and_suggestion():
210
  trust_tip = random.choice(trust_tips)
211
  suggestion = random.choice(suggestions)
212
  return trust_tip, suggestion
 
213
 
214
 
215
 
 
247
  <h3 class="competence">Competence Trust:</h3>
248
  <p>What competencies can I trust you for?</p>
249
  """, unsafe_allow_html=True)
250
+ st.markdown("For detailed descriptions, visit [Academy](https://www.trustifier.ai)")
251
 
252
 
253
 
 
309
  return ["Error occurred during Google search"]
310
 
311
 
312
+
313
  # RAG response function
314
  def rag_response(query):
315
  try:
 
348
  You are an expert copywriter specializing in creating high-quality marketing content that integrates TrustBuilders® into various content formats. Your goal is to produce compelling, factual, and well-structured material that adheres to the following guidelines and based on knowledge base:
349
  **GENERAL INSTRUCTIONS:**
350
  - **Consistency:** Maintain a uniform format across all content types.
351
+ - **Tone:** Use an active, engaging, and direct tone. Avoid flowery language and things like 'in the realm','beacon of hope'etc. Avoid complex or overly elaborate language.
 
352
  - **No Conclusions:** Do not include conclusions in your responses.
353
  - **Specificity:** Include relevant names, numbers like $dollars and years, programs, strategies, places, awards, actions.
 
354
  - **Formatting:** Avoid using HTML tags such as `<span>`, `<i>`, or others, except for the registered trademark symbol (®). Ensure that numerical values are properly formatted with spaces (e.g., 750 billion to 1 trillion). Do not use bold, italics, or other text styling for numbers.
355
+ - **Trademark Usage:** Only use the registered trademark symbol (®) with these brands: TrustLogic, TrustBuilder/TrustBuilders, Six Buckets of Trust, TrustifierAI. Do not use (®) with other brands.
 
356
  **CONTENT TYPES AND FORMATS:**
357
  1. **Annual Reports or Articles:**
358
  - Guidelines: Look in knowledge base for guiding principles for generation of marketing copy before generating response.
359
  - **Introduction:** Start with "Here is a draft of your [Annual Report/Article]. Feel free to suggest further refinements."
360
+ - **Trademark Usage:** Only use the registered trademark symbol (®) with these brands: TrustLogic, TrustBuilder/TrustBuilders, Six Buckets of Trust, TrustifierAI. Do not use (®) with other brands.
361
  - **Structure:**
362
  - **Headline:** This will contain the Principles.The headline should not mention TrustBuilders® or any trust buckets directly.
363
  - **Content:**
364
+ - One main heading followed by 3-4 detailed paragraphs summarizing key content (without source links included and without any headings).
365
  - **Perspective:** Write as if you are part of the organization (using "we"), emphasizing togetherness and collective effort.
366
  - **Sub-Headings (After Summary):**
367
  1. **List of TrustBuilders® used :** Strictly return list of relevant trust builders used with facts and figures with embedded URL source links everytime.
368
+ 2. **Heuristics Used:** Provide 3-5 heuristics from the following list that are relevant to the content. Ensure to integrate them in a way that highlights their relevance to the content:Social Proof, Scarcity, Authority, Reciprocity, Consistency, Liking, Anchoring, Contrast, Urgency, Simplicity, Storytelling, Emotion, Framing, Loss Aversion, Recency, Frequency, Congruence, Availability, Commitment, Halo Effect, Ingroup Bias, Reciprocal Concessions (Door-in-the-Face), Priming, Cognitive Ease, Affect Heuristic, Endowment Effect, Decoy Effect, Foot-in-the-Door, Pacing, Zeigarnik Effect.
369
  3. **Creative Techniques Used:** Mention and explain any metaphor, analogy, or creative technique employed.
370
+ - **Word Count:** Strictly follow word count instruction if given in user prompt. Main [Content] must meet the specified word count.Do not include the sub-heading sections in the word count limit.
371
+
 
 
 
372
  2. **Social Media Posts:**
373
  - **Format:** Create engaging posts with relevant hashtags.
374
  - **Intro Line:** Start with "Here is a draft of your social media post. Feel free to suggest further refinements."
375
  - **Content:** Ensure the post is concise, impactful, and designed to engage the audience.
376
  - **Additional Requirements:** Avoid mentioning trust buckets as hashtags or in the post copy. Ensure source links and trust builders are not included in the post text.
377
  - **List of TrustBuilders® used :** Provide a list of relevant TrustBuilders used with facts and figures and embedded URL source links.
378
+ - **Word Count:** Strictly follow word count instruction if given in user prompt . Main [body] must meet the specified word count.
379
  3. **Sales Conversations or Ad Copy:**
380
  - **Format:** Create a structured conversation or ad copy with clear messaging.
381
  - **Intro Line:** Start with "Here is a draft of your [Sales Conversation/Ad Copy]. Feel free to suggest further refinements."
382
  - **Content:** Include persuasive elements with integrated TrustBuilders®.
383
  - **List of TrustBuilders® used :** Provide a list of relevant TrustBuilders used with facts and figures and embedded URL source links.
 
384
 
385
  4. **Emails, Newsletters, Direct Marketing Letters:**
386
  - **Format:** Structure properly as an email or letter without any sub-headings.
387
  - **Intro Line:** Start with "Here is a draft of your [Email/Newsletter/Letter]. Feel free to suggest further refinements."
388
+ - **Content:** Focus on clear, concise messaging with a call to action where appropriate. Do-not include source links here or any links.
389
+ - **Subject:** Give proper subject for emails.
390
  - **Additional Requirements:** Ensure that trust builders are not mentioned in the email or letter body unless specifically required. Do-not include source links.
391
  - **Sub-Headings (At bottom):**
392
  1. **List of TrustBuilders® used :** Provide List of relevant trust builders used with facts and figures and with embedded source links.
393
+ 2. **Heuristics Used:** Provide 3-5 heuristics names only from the following list that are relevant to the content :Social Proof, Scarcity, Authority, Reciprocity, Consistency, Liking, Anchoring, Contrast, Urgency, Simplicity, Storytelling, Emotion, Framing, Loss Aversion, Recency, Frequency, Congruence, Availability, Commitment, Halo Effect, Ingroup Bias, Reciprocal Concessions (Door-in-the-Face), Priming, Cognitive Ease, Affect Heuristic, Endowment Effect, Decoy Effect, Foot-in-the-Door, Pacing, Zeigarnik Effect.
394
  3. **Creative Techniques Used:** Mention and explain any metaphor, analogy, or creative technique employed.
395
+ - **Word Count:** Strictly follow word count instruction if given in user prompt . Main body [Content] must meet the specified word count. Do not include the sub-heading sections in the word count limit.
 
396
  5. **TRUST-BASED QUERIES:**
397
+ - When a query specifically seeks proof points or content related to trust builders or trust buckets, follow these guidelines:
398
  - **TrustBuilder® Integration:** Find and list a minimum of 15 Trust Builders points directly followed by relevant source links.
399
  - **Intro Line:** Start with "Here are some [Bucket name] TrustBuilders®. Let me know if you want to refine the results or find more."
400
+ - **TrustBuilders® Formatting :** Strictly categorize TrustBuilders® correctly into the following sections:
 
401
  - ### Organization:** List details about the organization. do-not mention any heading within points.
402
  - ### People:** List individuals associated with the TrustBuilder®. do-not mention any heading within points.
403
  - ### Offers/Services:** Detail the offers or services provided. do-not mention any heading within points.
 
405
  - Write in bullet points under each heading.
406
  - Each point should not contain any sub-headings.
407
  - Give source links with each point.
408
+ - Maintain consistent format.
409
  - No conclusions at the end of content unless specifically requested.
410
  - **Trust Bucket Focus:** Do not mix trust buckets; keep responses focused on the requested area.
411
  - *Refer to the knowledge base for Guiding Principles.*
 
412
  **GENERAL QUERIES:**
413
  - For general content like blogs or reports always refer knowledge base first, focus on the overall flow and structure without explicitly mentioning trust metrics unless requested.
 
 
414
  """
415
 
416
 
 
531
  <div class="section-container">
532
  <div class="section">
533
  <h2>Find</h2>
534
+ <p>Discover all your great TrustBuilders®. <br> Example: Find Development Trust Builders® for World Vision
535
  </div>
536
  <div class="section">
537
  <h2>Create</h2>
538
+ <p>Generate trust-optimised solutions : <br>Example: Find World Vision development TrustBuilders®. Then use them to write a 200-word annual report article. Enthusiastic tone.</p>
539
  </div>
540
  <div class="section">
541
  <h2>Trust-optimise</h2>
 
614
  try:
615
  # Generate response using the agent executor
616
  output = agent_executor.invoke({
617
+ "input": f"{prompt} .Strictly follow words (write more than the mentioned words in case of article or news letter) and already mention instructions.Handle problematic text (Usually it is related to numbers, figures and text nearby )clean it up make spaced so that it is readable and properly formatted for display in a web application. Avoid any unusual line breaks or formatting issues. Always provide sources links with trust builders. Find right trust builders, do not mix please. ",
618
 
619
  "chat_history": st.session_state.chat_history
620
  })
 
624
  cleaned_text = clean_text(full_response)
625
  cleaned_text = re.sub(r'<[^>]*>', '', cleaned_text)
626
 
627
+
628
 
629
  #cleaned_text = re.sub(r'</span>', '', cleaned_text)
630
  #cleaned_text = re.sub(r'<span[^>]*>', '', cleaned_text)
631
  # Display the response
632
+
633
  trust_tip, suggestion = get_trust_tip_and_suggestion()
634
 
635
+ #combined_text = f"{cleaned_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
 
636
  combined_text = f"{cleaned_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
637
+
638
+ st.markdown(combined_text,unsafe_allow_html=True)
639
+
640
  #seprtor= st.markdown("---") # Add a separator
641
  #t_tip= st.markdown(f"**Trust Tip**: {trust_tip}")
642
  #s_sug- st.markdown(f"**Suggestion**: {suggestion}")
 
651
  full_response = "I apologize, but an error occurred while generating the response. Please try again."
652
  st.write(full_response)
653
 
654
+ # Add AI response to chat history
 
 
 
 
655
 
656
+ st.session_state.chat_history.append({"role": "assistant", "content": cleaned_text})
657
+ copy_to_clipboard(cleaned_text)