import streamlit as st
import os
from langgraphagenticai.ui.uiconfigfile import Config
class LoadStreamlitUI:
def __init__(self):
self.config = Config()
self.user_controls = {}
def _inject_custom_css(self):
"""Inject custom CSS with light purple-green background and white fonts"""
st.markdown("""
""", unsafe_allow_html=True)
def load_streamlit_ui(self):
# Page config
st.set_page_config(
page_title="🤖 " + self.config.get_page_title(),
layout="wide",
initial_sidebar_state="expanded"
)
st.session_state.timeframe = ''
st.session_state.IsFetchButtonClicked = False
# Inject custom CSS
self._inject_custom_css()
# Custom header with animated robot icon (bouncing up and down)
st.markdown(f"""
""", unsafe_allow_html=True)
# Animated chatbot icon at bottom right
st.markdown("""
🤖
""", unsafe_allow_html=True)
with st.sidebar:
# Get options from config
llm_options = self.config.get_llm_options()
usecase_options = self.config.get_usecase_options()
# AI Configuration section header
st.markdown("", unsafe_allow_html=True)
# LLM selection
self.user_controls["selected_llm"] = st.selectbox(
"Select LLM",
llm_options,
help="Choose your preferred Language Model"
)
if self.user_controls["selected_llm"] == 'Groq':
# Model selection
model_options = self.config.get_groq_model_options()
self.user_controls["selected_groq_model"] = st.selectbox(
"Select Model",
model_options,
help="Choose a Groq model variant"
)
self.user_controls["GROQ_API_KEY"] = st.session_state["GROQ_API_KEY"] = st.text_input(
"API Key",
type="password",
placeholder="Enter your Groq API key"
)
# Validate API key
if not self.user_controls["GROQ_API_KEY"]:
st.warning("⚠️ Please enter your GROQ API key to proceed. Don't have one? Get it here: [Groq Console](https://console.groq.com/keys)")
# Divider
st.markdown("", unsafe_allow_html=True)
# Use Case section header
st.markdown("", unsafe_allow_html=True)
# Usecase selection
self.user_controls["selected_usecase"] = st.selectbox(
"Select Usecases",
usecase_options,
help="Choose your application use case"
)
if self.user_controls["selected_usecase"] =="Chatbot with Web Search" or self.user_controls["selected_usecase"] =="AI News":
os.environ["TAVILY_API_KEY"]=self.user_controls["TAVILY_API_KEY"]=st.session_state["TAVILY_API_KEY"]=st.text_input("TAVILY API KEY",type="password", placeholder="Enter your TAVILY API key")
# Validate API key
if not self.user_controls["TAVILY_API_KEY"]:
st.warning("⚠️ Please enter your TAVILY_API_KEY key to proceed. Don't have? refer : https://app.tavily.com/home")
if self.user_controls['selected_usecase']=="AI News":
st.subheader("📰 AI News Explorer ")
with st.sidebar:
time_frame = st.selectbox(
"📅 Select Time Frame",
["Daily", "Weekly", "Monthly"],
index=0
)
if st.button("🔍 Fetch Latest AI News", use_container_width=True):
st.session_state.IsFetchButtonClicked = True
st.session_state.timeframe = time_frame
elif self.user_controls["selected_usecase"] == "Research Assistant":
st.info("🔬 **Research Assistant Features:**\n\n"
"• **ArXiv Search**: Access academic papers and research\n"
"• **Web Search**: Complement research with general web results\n"
"• **No API Key Required**: ArXiv is free to use\n\n"
"Perfect for literature reviews, academic research, and finding relevant papers!")
# Still need TAVILY for web search component
os.environ["TAVILY_API_KEY"]=self.user_controls["TAVILY_API_KEY"]=st.session_state["TAVILY_API_KEY"]=st.text_input("TAVILY API KEY",type="password", placeholder="Enter your TAVILY API key for web search")
# Validate API key
if not self.user_controls["TAVILY_API_KEY"]:
st.warning("⚠️ Please enter your TAVILY_API_KEY for comprehensive research. Don't have? refer : https://app.tavily.com/home")
return self.user_controls