Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1536,55 +1536,57 @@ def validate_ai_output(ai_output, proof_points):
|
|
| 1536 |
return validated_output
|
| 1537 |
# Create the prompt template
|
| 1538 |
prompt_message = """
|
| 1539 |
-
|
| 1540 |
-
|
| 1541 |
-
|
| 1542 |
-
|
| 1543 |
-
|
| 1544 |
-
|
| 1545 |
-
|
| 1546 |
-
-
|
| 1547 |
-
-
|
| 1548 |
-
|
| 1549 |
-
|
| 1550 |
-
|
| 1551 |
-
|
| 1552 |
-
|
| 1553 |
-
|
| 1554 |
-
|
| 1555 |
-
|
| 1556 |
-
|
| 1557 |
-
|
| 1558 |
-
|
| 1559 |
-
|
| 1560 |
-
|
| 1561 |
-
|
| 1562 |
-
|
| 1563 |
-
|
| 1564 |
-
|
| 1565 |
-
|
| 1566 |
-
|
| 1567 |
-
-
|
| 1568 |
-
-
|
| 1569 |
-
-
|
| 1570 |
-
|
| 1571 |
-
|
| 1572 |
-
-
|
| 1573 |
-
|
| 1574 |
-
-
|
| 1575 |
-
-
|
| 1576 |
-
-
|
| 1577 |
-
|
| 1578 |
-
|
| 1579 |
-
-
|
| 1580 |
-
|
| 1581 |
-
-
|
| 1582 |
-
|
| 1583 |
-
|
| 1584 |
-
-
|
| 1585 |
-
-
|
| 1586 |
-
-
|
| 1587 |
-
|
|
|
|
|
|
|
| 1588 |
"""
|
| 1589 |
|
| 1590 |
|
|
@@ -1683,27 +1685,87 @@ def get_trust_tip_and_suggestion():
|
|
| 1683 |
suggestion = random.choice(suggestions)
|
| 1684 |
return trust_tip, suggestion
|
| 1685 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1686 |
|
| 1687 |
|
| 1688 |
def chatbot_response(message, history):
|
| 1689 |
global selected_dataset_ai
|
| 1690 |
global df_builder_pivot_str
|
| 1691 |
-
|
| 1692 |
try:
|
| 1693 |
selected_dataset_ai = read_ai_dataset_selection()
|
| 1694 |
-
|
| 1695 |
# Recompute DATAFRAME_PROOF_POINT based on the selected dataset
|
| 1696 |
df_builder_pivot_str = compute_dataframe_proof_point()
|
| 1697 |
-
|
|
|
|
|
|
|
|
|
|
| 1698 |
output = agent_executor.invoke({"input": message, "chat_history": chat_history})
|
| 1699 |
trust_tip, suggestion = get_trust_tip_and_suggestion()
|
| 1700 |
-
|
| 1701 |
-
|
| 1702 |
-
|
|
|
|
| 1703 |
# Add Trust Tip and Suggestion if not already in history
|
| 1704 |
if not any(f"**Trust Tip**: {trust_tip}" in entry["bot"] and f"**Suggestion**: {suggestion}" in entry["bot"] for entry in history):
|
| 1705 |
response += f"\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
|
| 1706 |
-
|
| 1707 |
# Save the interaction context
|
| 1708 |
history.extend(
|
| 1709 |
[
|
|
@@ -1711,7 +1773,6 @@ def chatbot_response(message, history):
|
|
| 1711 |
AIMessage(content=response),
|
| 1712 |
]
|
| 1713 |
)
|
| 1714 |
-
|
| 1715 |
return response
|
| 1716 |
except Exception as e:
|
| 1717 |
logger.error(f"Error generating chatbot response: {e}")
|
|
@@ -1721,7 +1782,6 @@ def chatbot_response(message, history):
|
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
-
|
| 1725 |
def read_ai_dataset_selection():
|
| 1726 |
global selected_dataset_ai
|
| 1727 |
return selected_dataset_ai
|
|
|
|
| 1536 |
return validated_output
|
| 1537 |
# Create the prompt template
|
| 1538 |
prompt_message = """
|
| 1539 |
+
|
| 1540 |
+
You are an expert copywriter specializing in creating high-quality marketing content that integrates Top-Scoring Statements for Each Trust Bucket into various formats. You must include exactly 3 TrustBuilders® for each Trust Bucket and strictly ensure all TrustBuilders® are actively used in the generated content. Please make content longer especially sales conversation.
|
| 1541 |
+
|
| 1542 |
+
**Listing Top-Scoring Statements**
|
| 1543 |
+
- Use the following format to display top-scoring statements:
|
| 1544 |
+
Top-scoring statements
|
| 1545 |
+
**Bucket Name**
|
| 1546 |
+
- TrustBuilder® Statement 1 [Percentage]
|
| 1547 |
+
- TrustBuilder® Statement 2 [Percentage]
|
| 1548 |
+
- TrustBuilder® Statement 3 [Percentage]
|
| 1549 |
+
|
| 1550 |
+
Generating Content**
|
| 1551 |
+
- Integrate **all listed TrustBuilders®** into the requested content format. Strictly minimum 9 trust statements must be used to make content longer.
|
| 1552 |
+
- Do not omit any TrustBuilders®—all must be actively and explicitly included in the content.
|
| 1553 |
+
- Maintain a **longer and detailed response**, using all the provided Trust statements to ensure comprehensive coverage.
|
| 1554 |
+
|
| 1555 |
+
**Content Guidelines**
|
| 1556 |
+
Use **all TrustBuilders®** in the content and make it longer.
|
| 1557 |
+
**General Rules**
|
| 1558 |
+
- Tone: Active, engaging, and professional. Avoid flowery or overly complex language.
|
| 1559 |
+
- Specificity: Include relevant names, numbers (e.g., dollars, years), programs, awards, strategies, or locations.
|
| 1560 |
+
---
|
| 1561 |
+
**Content Types**
|
| 1562 |
+
1. **Annual Reports/Articles**
|
| 1563 |
+
- Structure:
|
| 1564 |
+
- Headline
|
| 1565 |
+
- Main content (3-4 detailed paragraphs integrating all required TrustBuilders®).
|
| 1566 |
+
- Additional Sections:
|
| 1567 |
+
- List of TrustBuilders® Used : list minimum 9 top scoring statements retrieved
|
| 1568 |
+
- Heuristics Used: List 3-5 relevant heuristics.
|
| 1569 |
+
- Creative Techniques Used: Mention and explain any metaphor, analogy, or creative technique employed.
|
| 1570 |
+
2. **Sales Conversations/Ad Copy**
|
| 1571 |
+
-
|
| 1572 |
+
- Structure:
|
| 1573 |
+
Detailed conversation.
|
| 1574 |
+
- Intro line: "Here is a draft of your [Sales Conversation/Ad Copy]. Feel free to suggest further refinements."
|
| 1575 |
+
- Content structured using top scoring statements retrieved with clear messaging, integrating all required TrustBuilders®.
|
| 1576 |
+
- Additional Sections:
|
| 1577 |
+
- List of TrustBuilders® Used : list retreived trust statements 9 from top scoring.
|
| 1578 |
+
- Heuristics Used: List 3-5 relevant heuristics.
|
| 1579 |
+
- Creative Techniques Used: Mention and explain any creative elements used.
|
| 1580 |
+
3. **Emails, Newsletters, Direct Marketing Letters**
|
| 1581 |
+
- Intro Line: "Here is a draft of your [Email/Newsletter/Letter]. Feel free to suggest further refinements."
|
| 1582 |
+
- Content: Concise, actionable messaging with a call to action, integrating all required TrustBuilders®.
|
| 1583 |
+
- Additional Sections:
|
| 1584 |
+
- List of TrustBuilders® Used : list minimum 9 top scoring statements retrieved
|
| 1585 |
+
- Heuristics Used: List 3-5 relevant heuristics.
|
| 1586 |
+
- Creative Techniques Used: Highlight creative approaches used.
|
| 1587 |
+
#### **GENERAL QUERIES**
|
| 1588 |
+
- For blogs or reports, refer to the knowledge base first. Focus on overall flow and structure without mentioning trust metrics unless requested.
|
| 1589 |
+
|
| 1590 |
"""
|
| 1591 |
|
| 1592 |
|
|
|
|
| 1685 |
suggestion = random.choice(suggestions)
|
| 1686 |
return trust_tip, suggestion
|
| 1687 |
|
| 1688 |
+
def get_top_scoring_statements(dataset):
|
| 1689 |
+
"""
|
| 1690 |
+
Retrieve top-scoring statements for specific trust buckets based on dataset
|
| 1691 |
+
|
| 1692 |
+
Args:
|
| 1693 |
+
dataset (str): The selected dataset ('VW Customers' or 'VW Prospects')
|
| 1694 |
+
|
| 1695 |
+
Returns:
|
| 1696 |
+
str: Formatted top-scoring statements
|
| 1697 |
+
"""
|
| 1698 |
+
if dataset == "VW Customers":
|
| 1699 |
+
# Top statements for VW Customers
|
| 1700 |
+
top_statements = """
|
| 1701 |
+
Top Scoring Statements:
|
| 1702 |
+
|
| 1703 |
+
*Development*
|
| 1704 |
+
- We bring together the world's best talent in many disciplines to create your cars.(25%)
|
| 1705 |
+
- Building great and affordable cars is our foundation.(22%)
|
| 1706 |
+
- Our beginnings are a unique combination of investors and unions, and today 9 of our 20 board members are staff representatives.(18%)
|
| 1707 |
+
|
| 1708 |
+
*Benefit*
|
| 1709 |
+
- We bring together the world's best talent in many disciplines to create your cars.(23%)
|
| 1710 |
+
- We strongly focus on keeping and nurturing our team and have a 99.5% retention rate.(18%)
|
| 1711 |
+
- Employees are provided with extensive continuous training.(16%)
|
| 1712 |
+
|
| 1713 |
+
*Vision*
|
| 1714 |
+
- Our brands are ranked No. 2 and 5 in the reliability rankings.(27%)
|
| 1715 |
+
- Our technology and manufacturing capabilities are second to none.(22%)
|
| 1716 |
+
- We produce almost 9 million cars per year.(15%)
|
| 1717 |
+
|
| 1718 |
+
"""
|
| 1719 |
+
elif dataset == "VW Prospects":
|
| 1720 |
+
# Top statements for VW Prospects
|
| 1721 |
+
top_statements = """
|
| 1722 |
+
Top Scoring Statements:
|
| 1723 |
+
|
| 1724 |
+
*Stability*
|
| 1725 |
+
- We work with our unions in our restructuring and future plans.(21%)
|
| 1726 |
+
- We have learned from our mistakes in the Diesel Affair and made fundamental changes.(19%)
|
| 1727 |
+
- Building great and affordable cars is our foundation.(18%)
|
| 1728 |
+
|
| 1729 |
+
*Relationship*
|
| 1730 |
+
- We put a lot of emphasis on the interior experience and two of our cars have been ranked in the top 10. (24%)
|
| 1731 |
+
- We are at the forefront of technology to deliver better cars and driving experiences. (17%)
|
| 1732 |
+
- Our beginnings are a unique combination of investors and unions, and today 9 of our 20 board members are staff representatives. (17%)
|
| 1733 |
+
|
| 1734 |
+
*Competence*
|
| 1735 |
+
- At the heart of our decision-making is the long-term quality of life for all of us. (20%)
|
| 1736 |
+
- We put a lot of emphasis on the interior experience and two of our cars have been ranked in the top 10. (19%)
|
| 1737 |
+
- We are one of the longest-established car companies. (18%)
|
| 1738 |
+
|
| 1739 |
+
|
| 1740 |
+
|
| 1741 |
+
"""
|
| 1742 |
+
else:
|
| 1743 |
+
top_statements = "No specific trust statements available for this dataset."
|
| 1744 |
+
|
| 1745 |
+
return top_statements
|
| 1746 |
|
| 1747 |
|
| 1748 |
def chatbot_response(message, history):
|
| 1749 |
global selected_dataset_ai
|
| 1750 |
global df_builder_pivot_str
|
|
|
|
| 1751 |
try:
|
| 1752 |
selected_dataset_ai = read_ai_dataset_selection()
|
|
|
|
| 1753 |
# Recompute DATAFRAME_PROOF_POINT based on the selected dataset
|
| 1754 |
df_builder_pivot_str = compute_dataframe_proof_point()
|
| 1755 |
+
|
| 1756 |
+
# Get top-scoring statements based on selected dataset
|
| 1757 |
+
top_scoring_statements = get_top_scoring_statements(selected_dataset_ai)
|
| 1758 |
+
|
| 1759 |
output = agent_executor.invoke({"input": message, "chat_history": chat_history})
|
| 1760 |
trust_tip, suggestion = get_trust_tip_and_suggestion()
|
| 1761 |
+
|
| 1762 |
+
# Prepend top-scoring statements to the response
|
| 1763 |
+
response = f"**Selected Dataset: {selected_dataset_ai}**\n\n{top_scoring_statements}\n\n{output['output']}"
|
| 1764 |
+
|
| 1765 |
# Add Trust Tip and Suggestion if not already in history
|
| 1766 |
if not any(f"**Trust Tip**: {trust_tip}" in entry["bot"] and f"**Suggestion**: {suggestion}" in entry["bot"] for entry in history):
|
| 1767 |
response += f"\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
|
| 1768 |
+
|
| 1769 |
# Save the interaction context
|
| 1770 |
history.extend(
|
| 1771 |
[
|
|
|
|
| 1773 |
AIMessage(content=response),
|
| 1774 |
]
|
| 1775 |
)
|
|
|
|
| 1776 |
return response
|
| 1777 |
except Exception as e:
|
| 1778 |
logger.error(f"Error generating chatbot response: {e}")
|
|
|
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
|
|
|
| 1785 |
def read_ai_dataset_selection():
|
| 1786 |
global selected_dataset_ai
|
| 1787 |
return selected_dataset_ai
|