Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,51 +16,201 @@ st.set_page_config(
|
|
| 16 |
initial_sidebar_state="collapsed",
|
| 17 |
)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
st.markdown('<hr style="margin: 10px 0 20px 0; border: none; border-top: 1px solid #ddd;">', unsafe_allow_html=True)
|
| 22 |
-
|
| 23 |
-
# ---------- ENFORCE WHITE THEME ----------
|
| 24 |
st.markdown(
|
| 25 |
"""
|
| 26 |
<style>
|
|
|
|
|
|
|
|
|
|
| 27 |
body, .stApp {
|
| 28 |
background-color: #FFFFFF !important;
|
| 29 |
color: #1F1F1F !important;
|
|
|
|
| 30 |
}
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
background-color: #FFFFFF !important;
|
| 41 |
color: #000000 !important;
|
| 42 |
-
border:
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
background-color: #10A37F !important;
|
| 47 |
color: #FFFFFF !important;
|
| 48 |
-
border-radius:
|
| 49 |
border: none !important;
|
|
|
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
-
|
|
|
|
| 52 |
background-color: #0D8C6C !important;
|
| 53 |
}
|
| 54 |
-
[data-testid="stChatMessage"], div[data-testid="stMarkdownContainer"] {
|
| 55 |
-
background-color: #FFFFFF !important;
|
| 56 |
-
}
|
| 57 |
|
| 58 |
-
/* Hide
|
| 59 |
button[title="View fullscreen"] {
|
| 60 |
display: none !important;
|
| 61 |
}
|
| 62 |
|
| 63 |
-
/* Hide image expand/resize controls */
|
| 64 |
[data-testid="StyledFullScreenButton"] {
|
| 65 |
display: none !important;
|
| 66 |
}
|
|
@@ -69,33 +219,71 @@ st.markdown(
|
|
| 69 |
display: none !important;
|
| 70 |
}
|
| 71 |
|
| 72 |
-
/*
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
}
|
| 76 |
</style>
|
| 77 |
""",
|
| 78 |
unsafe_allow_html=True,
|
| 79 |
)
|
| 80 |
|
| 81 |
-
# ---------- HIDE STREAMLIT MENU & FOOTER ----------
|
| 82 |
-
st.markdown("""
|
| 83 |
-
<style>
|
| 84 |
-
#MainMenu {visibility: hidden;}
|
| 85 |
-
header {visibility: hidden;}
|
| 86 |
-
footer {visibility: hidden;}
|
| 87 |
-
div[data-testid="stDecoration"] {display: none;}
|
| 88 |
-
</style>
|
| 89 |
-
""", unsafe_allow_html=True)
|
| 90 |
-
|
| 91 |
SYSTEM_INSTRUCTION = """You are an elite marketing copywriter and TrustLogic expert assistant.
|
| 92 |
Your primary role is to find and present TrustBuilders® for organizations. TrustBuilders® are specific, measurable achievements organized into three categories:
|
|
|
|
| 93 |
**TRUSTBUILDER® REQUIREMENTS:**
|
| 94 |
1. **Organization TrustBuilders**: Corporate achievements, programs, initiatives with exact numbers and dates
|
| 95 |
2. **People TrustBuilders**: Named individuals (Full Name + Complete Title) with their specific achievements
|
| 96 |
3. **Offers/Services TrustBuilders**: Programs, services, products with measurable outcomes
|
|
|
|
| 97 |
**FORMAT FOR EACH TRUSTBUILDER:**
|
| 98 |
* [Complete statement with numbers, names, dates]. This [SPECIFIC benefit with numbers if possible] for [SPECIFIC audience with details]. ([Source](URL))
|
|
|
|
| 99 |
**CRITICAL RULES:**
|
| 100 |
- Use EXACT numbers (no "approximately", "over", "around")
|
| 101 |
- Include FULL names and complete titles
|
|
@@ -103,18 +291,17 @@ Your primary role is to find and present TrustBuilders® for organizations. Trus
|
|
| 103 |
- Active voice only (never "was recognized" - use "received recognition")
|
| 104 |
- End every point with: "This [specific benefit] for [specific detailed audience]."
|
| 105 |
- Use latest data from 2024–2027
|
|
|
|
| 106 |
**BANNED WORDS - NEVER USE:**
|
| 107 |
empower, enhance, foster, leverage, transform, drive, pioneer, showcase, underscore, exemplify, spearhead, pivotal, transformative, "set the stage", "we're proud", "came to fruition"
|
|
|
|
| 108 |
**WRITING STYLE:**
|
| 109 |
- Professional and specific
|
| 110 |
- Data-driven with metrics
|
| 111 |
- Clear and actionable
|
| 112 |
- Use "we" voice when referring to the organization
|
| 113 |
- Never use vague claims without numbers
|
| 114 |
-
|
| 115 |
-
Always conclude your response with:
|
| 116 |
-
---
|
| 117 |
-
*For detailed analysis and information, visit [trustlogic.center](https://trustlogic.center) for comprehensive copy generation and brand analysis.*
|
| 118 |
When answering questions:
|
| 119 |
1. First check knowledge base for TrustLogic methodology
|
| 120 |
2. If user asks to "find TrustBuilders" for an organization, search the web extensively
|
|
@@ -123,25 +310,31 @@ When answering questions:
|
|
| 123 |
5. End with the trustlogic.center footer
|
| 124 |
"""
|
| 125 |
|
| 126 |
-
|
| 127 |
KB_PROMPT_TEMPLATE = PromptTemplate(
|
| 128 |
template="""You are an expert on TrustLogic methodology. Use the context below to answer accurately.
|
|
|
|
| 129 |
Context:
|
| 130 |
{context_str}
|
|
|
|
| 131 |
Question: {query_str}
|
|
|
|
| 132 |
Instructions:
|
| 133 |
- Answer based on the context provided
|
| 134 |
- Be specific and cite relevant TrustLogic concepts
|
| 135 |
- If the context doesn't fully answer the question, say so
|
| 136 |
- Keep your answer clear and professional
|
| 137 |
- Never mention that you're using a "knowledge base" - just provide the answer naturally
|
|
|
|
| 138 |
Answer:"""
|
| 139 |
)
|
| 140 |
|
| 141 |
WEB_SEARCH_PROMPT = """You are an expert at finding TrustBuilders® for organizations.
|
|
|
|
| 142 |
User's request: {query}
|
|
|
|
| 143 |
Web Search Results:
|
| 144 |
{web_results}
|
|
|
|
| 145 |
Instructions:
|
| 146 |
- Extract specific, measurable achievements from the search results
|
| 147 |
- Format as TrustBuilders® with complete details
|
|
@@ -151,6 +344,7 @@ Instructions:
|
|
| 151 |
- Use active voice only
|
| 152 |
- If finding TrustBuilders, provide at least 5 per category (Organization, People, Offers/Services)
|
| 153 |
- ALWAYS end your response with the trustlogic.center footer
|
|
|
|
| 154 |
Answer:"""
|
| 155 |
|
| 156 |
FOOTER_MESSAGE = "\n\n---\n*For detailed analysis and information, visit [trustlogic.center](https://trustlogic.center) for comprehensive copy generation and brand analysis.*"
|
|
@@ -179,27 +373,95 @@ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
| 179 |
|
| 180 |
# ---------- CHAT STATE ----------
|
| 181 |
if "messages" not in st.session_state:
|
| 182 |
-
st.session_state.messages = [
|
|
|
|
|
|
|
| 183 |
|
| 184 |
-
# ---------- DISPLAY
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
else:
|
| 189 |
-
st.markdown(f"**Chatbot:** {msg['content']}")
|
| 190 |
|
| 191 |
-
# ----------
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
-
# ----------
|
|
|
|
| 195 |
|
| 196 |
if not user_query:
|
| 197 |
st.stop()
|
| 198 |
|
| 199 |
-
|
| 200 |
-
st.
|
| 201 |
|
| 202 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
response_text = ""
|
| 204 |
placeholder = st.empty()
|
| 205 |
|
|
@@ -213,17 +475,21 @@ with st.spinner("Analyzing with TrustLogic intelligence..."):
|
|
| 213 |
|
| 214 |
# Decide if KB is enough or use web search
|
| 215 |
decision_prompt = f"""{SYSTEM_INSTRUCTION}
|
|
|
|
| 216 |
Evaluate if this knowledge base response adequately answers the user's question:
|
|
|
|
| 217 |
User Question: {user_query}
|
| 218 |
Knowledge Base Response: {str(kb_response)}
|
|
|
|
| 219 |
Decision criteria:
|
| 220 |
- Is the response relevant and about TrustLogic methodology or trust-building?
|
| 221 |
- Does it provide sufficient detail?
|
| 222 |
- Is this a request to "find TrustBuilders" for a specific organization? (If YES → USE_WEB)
|
|
|
|
| 223 |
Reply with only: USE_KB or USE_WEB"""
|
| 224 |
|
| 225 |
decision = client.chat.completions.create(
|
| 226 |
-
model="gpt-
|
| 227 |
messages=[{"role": "user", "content": decision_prompt}],
|
| 228 |
)
|
| 229 |
decision_text = decision.choices[0].message.content.strip()
|
|
@@ -252,10 +518,10 @@ Reply with only: USE_KB or USE_WEB"""
|
|
| 252 |
if chunk.choices[0].delta.content:
|
| 253 |
token = chunk.choices[0].delta.content
|
| 254 |
response_text += token
|
| 255 |
-
placeholder.markdown(f
|
| 256 |
|
| 257 |
if "trustlogic.center" not in response_text.lower():
|
| 258 |
response_text += FOOTER_MESSAGE
|
| 259 |
|
| 260 |
-
placeholder.markdown(f
|
| 261 |
-
st.session_state.messages.append({"role": "
|
|
|
|
| 16 |
initial_sidebar_state="collapsed",
|
| 17 |
)
|
| 18 |
|
| 19 |
+
# ---------- ENHANCED STYLING ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
st.markdown(
|
| 21 |
"""
|
| 22 |
<style>
|
| 23 |
+
@import url('https://fonts.googleapis.com/css2?family=Titillium+Web:wght@400;600;700&display=swap');
|
| 24 |
+
|
| 25 |
+
/* Base theme - clean white */
|
| 26 |
body, .stApp {
|
| 27 |
background-color: #FFFFFF !important;
|
| 28 |
color: #1F1F1F !important;
|
| 29 |
+
font-family: 'Titillium Web', sans-serif;
|
| 30 |
}
|
| 31 |
+
|
| 32 |
+
/* Main container styling */
|
| 33 |
+
.stApp {
|
| 34 |
+
max-width: 900px;
|
| 35 |
+
margin: 0 auto;
|
| 36 |
}
|
| 37 |
+
|
| 38 |
+
/* Logo container */
|
| 39 |
+
.logo-container {
|
| 40 |
+
text-align: center;
|
| 41 |
+
padding: 2rem 0 1rem 0;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
/* Trust Header */
|
| 45 |
+
.trust-header {
|
| 46 |
+
font-family: 'Titillium Web', sans-serif;
|
| 47 |
+
text-align: center;
|
| 48 |
+
margin-top: 40px;
|
| 49 |
+
margin-bottom: 10px;
|
| 50 |
+
font-size: 36px;
|
| 51 |
+
font-weight: 700;
|
| 52 |
+
line-height: 1.2;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/* Icon bar */
|
| 56 |
+
.icon-bar {
|
| 57 |
+
display: flex;
|
| 58 |
+
justify-content: center;
|
| 59 |
+
gap: 20px;
|
| 60 |
+
margin-top: 30px;
|
| 61 |
+
margin-bottom: 40px;
|
| 62 |
+
flex-wrap: wrap;
|
| 63 |
+
padding: 0 10px;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.icon-container {
|
| 67 |
+
position: relative;
|
| 68 |
+
display: inline-block;
|
| 69 |
+
text-align: center;
|
| 70 |
+
margin-bottom: 20px;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
/* Shared icon styling */
|
| 74 |
+
.icon-img {
|
| 75 |
+
object-fit: contain;
|
| 76 |
+
cursor: pointer;
|
| 77 |
+
transition: transform 0.2s;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/* Individually adjustable classes */
|
| 81 |
+
.ideate-icon, .write-icon, .find-icon, .analyse-icon, .chat-icon {
|
| 82 |
+
width: 30px;
|
| 83 |
+
height: 32px;
|
| 84 |
+
padding: 1px;
|
| 85 |
+
margin-top: 4px;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.icon-img:hover {
|
| 89 |
+
transform: scale(1.1);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
.tooltip-text {
|
| 93 |
+
visibility: hidden;
|
| 94 |
+
background-color: #222;
|
| 95 |
+
color: #fff;
|
| 96 |
+
text-align: left;
|
| 97 |
+
border-radius: 6px;
|
| 98 |
+
padding: 12px 14px;
|
| 99 |
+
position: absolute;
|
| 100 |
+
z-index: 10;
|
| 101 |
+
top: 60px;
|
| 102 |
+
left: 50%;
|
| 103 |
+
transform: translateX(-50%);
|
| 104 |
+
opacity: 0;
|
| 105 |
+
transition: opacity 0.3s;
|
| 106 |
+
font-size: 13px;
|
| 107 |
+
font-family: 'Titillium Web', sans-serif;
|
| 108 |
+
width: 280px;
|
| 109 |
+
max-width: 90vw;
|
| 110 |
+
word-wrap: break-word;
|
| 111 |
+
white-space: normal;
|
| 112 |
+
box-shadow: 0 6px 16px rgba(0,0,0,0.3);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
.icon-container:hover .tooltip-text,
|
| 116 |
+
.icon-container:active .tooltip-text {
|
| 117 |
+
visibility: visible;
|
| 118 |
+
opacity: 1;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/* Welcome prompt section */
|
| 122 |
+
.welcome-prompt {
|
| 123 |
+
text-align: center;
|
| 124 |
+
margin-top: 30px;
|
| 125 |
+
margin-bottom: 30px;
|
| 126 |
+
padding: 0 20px;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
.prompt-title {
|
| 130 |
+
font-size: 1.5rem;
|
| 131 |
+
font-weight: 600;
|
| 132 |
+
color: #1F1F1F;
|
| 133 |
+
margin-bottom: 10px;
|
| 134 |
+
font-family: 'Titillium Web', sans-serif;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.prompt-subtitle {
|
| 138 |
+
font-size: 0.95rem;
|
| 139 |
+
color: #6B7280;
|
| 140 |
+
font-family: 'Titillium Web', sans-serif;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/* Chat input styling */
|
| 144 |
+
.stChatInputContainer {
|
| 145 |
+
border-top: 1px solid #E5E7EB;
|
| 146 |
+
padding-top: 1rem;
|
| 147 |
+
margin-top: 2rem;
|
| 148 |
}
|
| 149 |
+
|
| 150 |
+
.stChatInput > div {
|
| 151 |
+
border-radius: 24px !important;
|
| 152 |
+
border: 2px solid #E5E7EB !important;
|
| 153 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.05);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
.stChatInput input {
|
| 157 |
background-color: #FFFFFF !important;
|
| 158 |
color: #000000 !important;
|
| 159 |
+
border: none !important;
|
| 160 |
+
padding: 0.75rem 1rem !important;
|
| 161 |
+
font-size: 0.95rem !important;
|
| 162 |
+
font-family: 'Titillium Web', sans-serif !important;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.stChatInput input::placeholder {
|
| 166 |
+
color: #9CA3AF !important;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/* Chat messages */
|
| 170 |
+
.chat-container {
|
| 171 |
+
margin-top: 2rem;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
.user-message {
|
| 175 |
+
background-color: #F3F4F6;
|
| 176 |
+
padding: 1rem 1.25rem;
|
| 177 |
+
border-radius: 18px;
|
| 178 |
+
margin: 0.5rem 0;
|
| 179 |
+
max-width: 85%;
|
| 180 |
+
margin-left: auto;
|
| 181 |
+
font-family: 'Titillium Web', sans-serif;
|
| 182 |
}
|
| 183 |
+
|
| 184 |
+
.bot-message {
|
| 185 |
+
background-color: #FFFFFF;
|
| 186 |
+
padding: 1rem 1.25rem;
|
| 187 |
+
border-radius: 18px;
|
| 188 |
+
margin: 0.5rem 0;
|
| 189 |
+
max-width: 85%;
|
| 190 |
+
border: 1px solid #E5E7EB;
|
| 191 |
+
font-family: 'Titillium Web', sans-serif;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/* Submit button styling */
|
| 195 |
+
button[kind="primary"] {
|
| 196 |
background-color: #10A37F !important;
|
| 197 |
color: #FFFFFF !important;
|
| 198 |
+
border-radius: 20px !important;
|
| 199 |
border: none !important;
|
| 200 |
+
padding: 0.5rem 1rem !important;
|
| 201 |
+
font-weight: 500 !important;
|
| 202 |
+
font-family: 'Titillium Web', sans-serif !important;
|
| 203 |
}
|
| 204 |
+
|
| 205 |
+
button[kind="primary"]:hover {
|
| 206 |
background-color: #0D8C6C !important;
|
| 207 |
}
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
+
/* Hide fullscreen button on images */
|
| 210 |
button[title="View fullscreen"] {
|
| 211 |
display: none !important;
|
| 212 |
}
|
| 213 |
|
|
|
|
| 214 |
[data-testid="StyledFullScreenButton"] {
|
| 215 |
display: none !important;
|
| 216 |
}
|
|
|
|
| 219 |
display: none !important;
|
| 220 |
}
|
| 221 |
|
| 222 |
+
/* Spinner */
|
| 223 |
+
.stSpinner > div {
|
| 224 |
+
border-top-color: #10A37F !important;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
/* Footer styling */
|
| 228 |
+
.footer-message {
|
| 229 |
+
font-size: 0.85rem;
|
| 230 |
+
color: #6B7280;
|
| 231 |
+
font-style: italic;
|
| 232 |
+
margin-top: 1rem;
|
| 233 |
+
padding-top: 1rem;
|
| 234 |
+
border-top: 1px solid #E5E7EB;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
/* Hide Streamlit branding */
|
| 238 |
+
#MainMenu {visibility: hidden;}
|
| 239 |
+
header {visibility: hidden;}
|
| 240 |
+
footer {visibility: hidden;}
|
| 241 |
+
div[data-testid="stDecoration"] {display: none;}
|
| 242 |
+
div[data-testid="stToolbar"] {display: none;}
|
| 243 |
+
|
| 244 |
+
/* Mobile responsive */
|
| 245 |
+
@media screen and (max-width: 600px) {
|
| 246 |
+
.trust-header {
|
| 247 |
+
font-size: 26px;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
.ideate-icon, .write-icon, .find-icon, .analyse-icon, .chat-icon {
|
| 251 |
+
width: 26px;
|
| 252 |
+
height: 26px;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
.tooltip-text {
|
| 256 |
+
font-size: 10px;
|
| 257 |
+
bottom: 10px;
|
| 258 |
+
top: auto !important;
|
| 259 |
+
left: 70%;
|
| 260 |
+
transform: translateX(-50%);
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
.prompt-title {
|
| 264 |
+
font-size: 1.2rem;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
.prompt-subtitle {
|
| 268 |
+
font-size: 0.85rem;
|
| 269 |
+
}
|
| 270 |
}
|
| 271 |
</style>
|
| 272 |
""",
|
| 273 |
unsafe_allow_html=True,
|
| 274 |
)
|
| 275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
SYSTEM_INSTRUCTION = """You are an elite marketing copywriter and TrustLogic expert assistant.
|
| 277 |
Your primary role is to find and present TrustBuilders® for organizations. TrustBuilders® are specific, measurable achievements organized into three categories:
|
| 278 |
+
|
| 279 |
**TRUSTBUILDER® REQUIREMENTS:**
|
| 280 |
1. **Organization TrustBuilders**: Corporate achievements, programs, initiatives with exact numbers and dates
|
| 281 |
2. **People TrustBuilders**: Named individuals (Full Name + Complete Title) with their specific achievements
|
| 282 |
3. **Offers/Services TrustBuilders**: Programs, services, products with measurable outcomes
|
| 283 |
+
|
| 284 |
**FORMAT FOR EACH TRUSTBUILDER:**
|
| 285 |
* [Complete statement with numbers, names, dates]. This [SPECIFIC benefit with numbers if possible] for [SPECIFIC audience with details]. ([Source](URL))
|
| 286 |
+
|
| 287 |
**CRITICAL RULES:**
|
| 288 |
- Use EXACT numbers (no "approximately", "over", "around")
|
| 289 |
- Include FULL names and complete titles
|
|
|
|
| 291 |
- Active voice only (never "was recognized" - use "received recognition")
|
| 292 |
- End every point with: "This [specific benefit] for [specific detailed audience]."
|
| 293 |
- Use latest data from 2024–2027
|
| 294 |
+
|
| 295 |
**BANNED WORDS - NEVER USE:**
|
| 296 |
empower, enhance, foster, leverage, transform, drive, pioneer, showcase, underscore, exemplify, spearhead, pivotal, transformative, "set the stage", "we're proud", "came to fruition"
|
| 297 |
+
|
| 298 |
**WRITING STYLE:**
|
| 299 |
- Professional and specific
|
| 300 |
- Data-driven with metrics
|
| 301 |
- Clear and actionable
|
| 302 |
- Use "we" voice when referring to the organization
|
| 303 |
- Never use vague claims without numbers
|
| 304 |
+
|
|
|
|
|
|
|
|
|
|
| 305 |
When answering questions:
|
| 306 |
1. First check knowledge base for TrustLogic methodology
|
| 307 |
2. If user asks to "find TrustBuilders" for an organization, search the web extensively
|
|
|
|
| 310 |
5. End with the trustlogic.center footer
|
| 311 |
"""
|
| 312 |
|
|
|
|
| 313 |
KB_PROMPT_TEMPLATE = PromptTemplate(
|
| 314 |
template="""You are an expert on TrustLogic methodology. Use the context below to answer accurately.
|
| 315 |
+
|
| 316 |
Context:
|
| 317 |
{context_str}
|
| 318 |
+
|
| 319 |
Question: {query_str}
|
| 320 |
+
|
| 321 |
Instructions:
|
| 322 |
- Answer based on the context provided
|
| 323 |
- Be specific and cite relevant TrustLogic concepts
|
| 324 |
- If the context doesn't fully answer the question, say so
|
| 325 |
- Keep your answer clear and professional
|
| 326 |
- Never mention that you're using a "knowledge base" - just provide the answer naturally
|
| 327 |
+
|
| 328 |
Answer:"""
|
| 329 |
)
|
| 330 |
|
| 331 |
WEB_SEARCH_PROMPT = """You are an expert at finding TrustBuilders® for organizations.
|
| 332 |
+
|
| 333 |
User's request: {query}
|
| 334 |
+
|
| 335 |
Web Search Results:
|
| 336 |
{web_results}
|
| 337 |
+
|
| 338 |
Instructions:
|
| 339 |
- Extract specific, measurable achievements from the search results
|
| 340 |
- Format as TrustBuilders® with complete details
|
|
|
|
| 344 |
- Use active voice only
|
| 345 |
- If finding TrustBuilders, provide at least 5 per category (Organization, People, Offers/Services)
|
| 346 |
- ALWAYS end your response with the trustlogic.center footer
|
| 347 |
+
|
| 348 |
Answer:"""
|
| 349 |
|
| 350 |
FOOTER_MESSAGE = "\n\n---\n*For detailed analysis and information, visit [trustlogic.center](https://trustlogic.center) for comprehensive copy generation and brand analysis.*"
|
|
|
|
| 373 |
|
| 374 |
# ---------- CHAT STATE ----------
|
| 375 |
if "messages" not in st.session_state:
|
| 376 |
+
st.session_state.messages = []
|
| 377 |
+
if "conversation_started" not in st.session_state:
|
| 378 |
+
st.session_state.conversation_started = False
|
| 379 |
|
| 380 |
+
# ---------- DISPLAY LOGO ----------
|
| 381 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
| 382 |
+
with col2:
|
| 383 |
+
st.image("Trust Logic Logo_RGB_Standard.png", width=180)
|
|
|
|
|
|
|
| 384 |
|
| 385 |
+
# ---------- WELCOME SCREEN OR CHAT ----------
|
| 386 |
+
if not st.session_state.conversation_started:
|
| 387 |
+
st.markdown("""
|
| 388 |
+
<div class="trust-header">
|
| 389 |
+
<span style="color:teal;">[</span>
|
| 390 |
+
<span style="color:black;">Let's build some trust!</span>
|
| 391 |
+
<span style="color:teal;">]</span>
|
| 392 |
+
</div>
|
| 393 |
+
|
| 394 |
+
<div class="icon-bar">
|
| 395 |
+
<div class="icon-container">
|
| 396 |
+
<img src="https://huggingface.co/spaces/trustlogic/temporary-trustlogic-batch/resolve/main/Screenshot%202025-08-14%20at%208.37.38%E2%80%AFPM.png" class="icon-img ideate-icon" alt="Ideate">
|
| 397 |
+
<div class="tooltip-text">
|
| 398 |
+
<strong>Ideate</strong><br>
|
| 399 |
+
Ask me which Trust Buckets® are most important and brainstorm trust-building ideas for your target audience. Tell me your ideas and audience and brainstorm with me.
|
| 400 |
+
</div>
|
| 401 |
+
</div>
|
| 402 |
+
<div class="icon-container">
|
| 403 |
+
<img src="https://huggingface.co/spaces/trustlogic/temporary-trustlogic-batch/resolve/main/write.png" class="icon-img write-icon" alt="Write">
|
| 404 |
+
<div class="tooltip-text">
|
| 405 |
+
<strong>Write</strong><br>
|
| 406 |
+
Tell me what you want to write and your audience. Tell me which Trust Buckets® you want to fill – or ask me to propose the most important ones.
|
| 407 |
+
</div>
|
| 408 |
+
</div>
|
| 409 |
+
<div class="icon-container">
|
| 410 |
+
<img src="https://huggingface.co/spaces/trustlogic/temporary-trustlogic-batch/resolve/main/find.png" class="icon-img find-icon" alt="Find">
|
| 411 |
+
<div class="tooltip-text">
|
| 412 |
+
<strong>Find</strong><br>
|
| 413 |
+
You probably have a vast treasure trove of unused trust equity sitting on the internet. I am trained to find it and show you verifiable sources. Use the Quick Start Menu to make it easy.
|
| 414 |
+
</div>
|
| 415 |
+
</div>
|
| 416 |
+
<div class="icon-container">
|
| 417 |
+
<img src="https://huggingface.co/spaces/trustlogic/temporary-trustlogic-batch/resolve/main/Analyse.png" class="icon-img analyse-icon" alt="Analyse">
|
| 418 |
+
<div class="tooltip-text">
|
| 419 |
+
<strong>Analyse</strong><br>
|
| 420 |
+
I can analyse for you which Trust Buckets® a content piece fills. Paste the URL or copy into the chat field and ask me to tell you which Trust Buckets® are filled and how. You can also do this for competitor websites. I can also give you top-level scores.
|
| 421 |
+
</div>
|
| 422 |
+
</div>
|
| 423 |
+
<div class="icon-container">
|
| 424 |
+
<img src="https://huggingface.co/spaces/trustlogic/temporary-trustlogic-batch/resolve/main/chat.png" class="icon-img chat-icon" alt="Chat">
|
| 425 |
+
<div class="tooltip-text">
|
| 426 |
+
<strong>Chat</strong><br>
|
| 427 |
+
Tell me to take the role of your audience. Use the Quick Start Menu or describe your audience. Then let's ideate and create trust-optimised content together.
|
| 428 |
+
</div>
|
| 429 |
+
</div>
|
| 430 |
+
</div>
|
| 431 |
+
|
| 432 |
+
<div class="welcome-prompt">
|
| 433 |
+
<div class="prompt-title">
|
| 434 |
+
How can TrustAI® help me?
|
| 435 |
+
</div>
|
| 436 |
+
<div class="prompt-subtitle">
|
| 437 |
+
(Replace the brand and industry in the prompt then hit enter.)
|
| 438 |
+
</div>
|
| 439 |
+
</div>
|
| 440 |
+
""", unsafe_allow_html=True)
|
| 441 |
+
else:
|
| 442 |
+
# Display conversation history
|
| 443 |
+
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
| 444 |
+
for msg in st.session_state.messages:
|
| 445 |
+
if msg["role"] == "user":
|
| 446 |
+
st.markdown(f'<div class="user-message">{msg["content"]}</div>', unsafe_allow_html=True)
|
| 447 |
+
else:
|
| 448 |
+
st.markdown(f'<div class="bot-message">{msg["content"]}</div>', unsafe_allow_html=True)
|
| 449 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 450 |
|
| 451 |
+
# ---------- USER INPUT ----------
|
| 452 |
+
user_query = st.chat_input("I'm a [position] for the [industry]. How can TrustLogic® help me?")
|
| 453 |
|
| 454 |
if not user_query:
|
| 455 |
st.stop()
|
| 456 |
|
| 457 |
+
# Mark conversation as started
|
| 458 |
+
st.session_state.conversation_started = True
|
| 459 |
|
| 460 |
+
# Add user message
|
| 461 |
+
st.session_state.messages.append({"role": "user", "content": user_query})
|
| 462 |
+
st.markdown(f'<div class="user-message">{user_query}</div>', unsafe_allow_html=True)
|
| 463 |
+
|
| 464 |
+
# ---------- RESPONSE LOGIC ----------
|
| 465 |
response_text = ""
|
| 466 |
placeholder = st.empty()
|
| 467 |
|
|
|
|
| 475 |
|
| 476 |
# Decide if KB is enough or use web search
|
| 477 |
decision_prompt = f"""{SYSTEM_INSTRUCTION}
|
| 478 |
+
|
| 479 |
Evaluate if this knowledge base response adequately answers the user's question:
|
| 480 |
+
|
| 481 |
User Question: {user_query}
|
| 482 |
Knowledge Base Response: {str(kb_response)}
|
| 483 |
+
|
| 484 |
Decision criteria:
|
| 485 |
- Is the response relevant and about TrustLogic methodology or trust-building?
|
| 486 |
- Does it provide sufficient detail?
|
| 487 |
- Is this a request to "find TrustBuilders" for a specific organization? (If YES → USE_WEB)
|
| 488 |
+
|
| 489 |
Reply with only: USE_KB or USE_WEB"""
|
| 490 |
|
| 491 |
decision = client.chat.completions.create(
|
| 492 |
+
model="gpt-4o",
|
| 493 |
messages=[{"role": "user", "content": decision_prompt}],
|
| 494 |
)
|
| 495 |
decision_text = decision.choices[0].message.content.strip()
|
|
|
|
| 518 |
if chunk.choices[0].delta.content:
|
| 519 |
token = chunk.choices[0].delta.content
|
| 520 |
response_text += token
|
| 521 |
+
placeholder.markdown(f'<div class="bot-message">{response_text}▌</div>', unsafe_allow_html=True)
|
| 522 |
|
| 523 |
if "trustlogic.center" not in response_text.lower():
|
| 524 |
response_text += FOOTER_MESSAGE
|
| 525 |
|
| 526 |
+
placeholder.markdown(f'<div class="bot-message">{response_text}</div>', unsafe_allow_html=True)
|
| 527 |
+
st.session_state.messages.append({"role": "assistant", "content": response_text})
|