Drop files here
or click to upload
import streamlit as st
import requests
# ======================
# API CONFIG
# ======================
API_ENDPOINT = "https://emea.snaplogic.com/api/1/rest/slsched/feed/ConnectFasterInc/snapLogic4snapLogic/Bootcamp_EMEA_August_2025/CRM_retriver_Chandra%20Task"
AUTH_TOKEN = "Bearer 111222"
# ======================
# PAGE CONFIG
# ======================
st.set_page_config(page_title="CRM Chatbot", page_icon="💬", layout="centered")
# ======================
# CSS STYLE
# ======================
st.markdown("""
<style>
/* Page background & font */
body, .block-container {
font-family: 'Courier New', monospace;
background-color: #f4f1e3;
color: #3b2f2f;
}
/* Chat bubbles */
.chat-bubble-user {
background-color: #ffdb99;
color: #3b2f2f;
padding: 10px 14px;
border-radius: 10px;
margin: 5px;
max-width: 75%;
align-self: flex-end;
box-shadow: 2px 2px 0px #b38b4d;
}
.chat-bubble-bot {
background-color: #a7c7e7;
color: #1c1c1c;
padding: 10px 14px;
border-radius: 10px;
margin: 5px;
max-width: 75%;
align-self: flex-start;
box-shadow: 2px 2px 0px #5a7d9a;
}
.chat-container {
display: flex;
flex-direction: column;
}
</style>
""", unsafe_allow_html=True)
# ======================
# TITLE
# ======================
st.markdown("<h1 style='color:#b35a00;'>🕹 CRM Chatbot</h1>", unsafe_allow_html=True)
st.markdown("<p style='color:#5a4636;'>Ask anything about CRM opportunities and get your answers here.</p>", unsafe_allow_html=True)
# ======================
# SESSION STATE
# ======================
if "messages" not in st.session_state:
st.session_state.messages = []
# ======================
# API CALL FUNCTION
# ======================
def query_api(question):
headers = {
"Authorization": AUTH_TOKEN,
"Content-Type": "application/json"
}
payload = [{"Question": question}]
try:
response = requests.post(API_ENDPOINT, headers=headers, json=payload, timeout=30)
response.raise_for_status()
data = response.json()
if isinstance(data, list) and "Response" in data[0]:
return data[0]["Response"]
else:
return "⚠️ Unexpected response format from API."
except Exception as e:
return f"❌ API error: {e}"
# ======================
# INPUT & SEND BUTTON
# ======================
user_question = st.text_input("💭 Your Question:", placeholder="Type your CRM question here...")
if st.button("🚀 Send"):
if user_question.strip():
st.session_state.messages.append({"role": "user", "content": user_question})
with st.spinner("🤖 Thinking..."):
bot_reply = query_api(user_question)
st.session_state.messages.append({"role": "bot", "content": bot_reply})
else:
st.warning("⚠️ Please enter a question.")
# ======================
# DISPLAY CHAT HISTORY
# ======================
st.markdown("### 📜 Conversation")
for msg in st.session_state.messages:
if msg["role"] == "user":
st.markdown(f"<div class='chat-container'><div class='chat-bubble-user'>👤 {msg['content']}</div></div>", unsafe_allow_html=True)
else:
st.markdown(f"<div class='chat-container'><div class='chat-bubble-bot'>🤖 {msg['content']}</div></div>", unsafe_allow_html=True)
# ======================
# FOOTER
# ======================
st.markdown("<hr>", unsafe_allow_html=True)
st.caption("💬 Powered by SnapLogic CRM API & Streamlit")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?