trygithubactions / streamlit_app.py
subashpoudel's picture
Implemented the analytics too in orchestrator
8ce97f0
raw
history blame
1.69 kB
import streamlit as st
import requests
# Your FastAPI endpoint
API_URL = "http://localhost:8000/api/analytics-chatbot" # change if deployed
st.set_page_config(page_title="Analytics Chatbot", page_icon="πŸ€–", layout="centered")
st.title("πŸ“Š Analytics Chatbot")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state["messages"] = []
# Display previous messages
for chat in st.session_state["messages"]:
role = "πŸ§‘ You" if chat["role"] == "user" else "πŸ€– Bot"
with st.chat_message(chat["role"]):
st.markdown(f"**{role}:** {chat['content']}")
# User input box
if prompt := st.chat_input("Ask something about analytics..."):
# Store user message
st.session_state["messages"].append({"role": "user", "content": prompt})
# Show user message
with st.chat_message("user"):
st.markdown(f"**πŸ§‘ You:** {prompt}")
try:
# Call FastAPI backend
response = requests.post(API_URL, json={"message": prompt})
if response.status_code == 200:
bot_reply = response.json()
# bot_reply = f"**Endpoint:** {data['endpoint']}\n\n" \
# f"**Parameters:** `{data['parameters']}`\n\n" \
# f"**Response:** {data['response']}"
else:
bot_reply = f"⚠️ Error {response.status_code}: {response.text}"
except Exception as e:
bot_reply = f"❌ Failed to connect to API: {e}"
# Store bot message
st.session_state["messages"].append({"role": "assistant", "content": bot_reply['response']})
# Show bot reply
with st.chat_message("assistant"):
st.json(bot_reply['response'])