Drop files here
or click to upload
import streamlit as st
import requests
import json
# --- API Details ---
API_ENDPOINT_URL = "https://emea.snaplogic.com/api/1/rest/slsched/feed/ConnectFasterInc/snapLogic4snapLogic/Bootcamp_EMEA_August_2025/CRM_retriver_Chandra%20Task"
AUTHORIZATION_TOKEN = "111222"
# --- Streamlit App Setup ---
st.set_page_config(page_title="CRM Chatbot", page_icon="🤖")
st.title("CRM Chatbot 💬")
# --- Function to interact with the API ---
def get_api_response(question):
"""
Sends a user's question to the specified API and returns the response.
"""
headers = {
"Authorization": AUTHORIZATION_TOKEN,
"Content-Type": "application/json"
}
payload = [{"Question": question}]
try:
response = requests.post(API_ENDPOINT_URL, headers=headers, data=json.dumps(payload))
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
api_response_data = response.json()
if api_response_data and isinstance(api_response_data, list) and "Response" in api_response_data[0]:
return api_response_data[0]["Response"]
else:
return "Error: Unexpected response format from the API."
except requests.exceptions.RequestException as e:
return f"An error occurred while calling the API: {e}"
# --- Chat Interface ---
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
st.session_state.messages.append({"role": "assistant", "content": "Hello! I'm a CRM assistant. How can I help you today?"})
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# React to user input
if prompt := st.chat_input("Ask a question about your CRM data..."):
# Display user message in chat message container
st.chat_message("user").markdown(prompt)
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
# Get response from the API
with st.spinner("Thinking..."):
api_response = get_api_response(prompt)
# Display assistant response in chat message container
with st.chat_message("assistant"):
st.markdown(api_response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": api_response})
import pandas as pd
import numpy as np
# Create some sample data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Add some text
st.title('Simple Streamlit App')
st.write('Welcome! This is a basic demonstration of Streamlit.')
# Display the data
st.subheader('Sample Data')
df = pd.DataFrame({
'x': x,
'y': y
})
st.dataframe(df.head())
# Create some plots
st.subheader('Line Plot')
st.line_chart(df.set_index('x'))
st.subheader('Area Chart')
st.area_chart(df.set_index('x'))
# Add interactive elements
st.subheader('Interactive Elements')
name = st.text_input('Enter your name')
if name:
st.write(f'Hello {name}!')
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?