Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import os | |
| from src.langgraphagenticai.ui.uiconfigfile import Config | |
| # This class is responsible for creating and managing the Streamlit user interface (UI) | |
| # for the LangGraph Agentic AI application. | |
| class LoadStreamlitUI: | |
| def __init__(self): | |
| # Initialize the configuration object (reads from uiconfigfile.ini) | |
| self.config = Config() | |
| # A dictionary to store user-selected UI control values (e.g., LLM, model, API keys) | |
| self.user_controls = {} | |
| # Main function to load and display all Streamlit UI components | |
| def load_streamlit_ui(self): | |
| # Set page configuration such as title and layout | |
| st.set_page_config( | |
| page_title="π€ " + self.config.get_page_title(), | |
| layout="wide" | |
| ) | |
| # Display the main page header | |
| st.header("π€ " + self.config.get_page_title()) | |
| # Initialize session variables for controlling UI behavior | |
| st.session_state.timeframe = '' | |
| st.session_state.IsFetchButtonClicked = False | |
| # Everything inside 'with st.sidebar' will appear in the left sidebar | |
| with st.sidebar: | |
| # Retrieve configuration options (LLMs and Use Cases) | |
| llm_options = self.config.get_llm_options() | |
| usecase_options = self.config.get_usecase_options() | |
| # Dropdown to select which LLM provider to use (e.g., Groq) | |
| self.user_controls["selected_llm"] = st.selectbox("Select LLM", llm_options) | |
| # If user chooses 'Groq' as LLM, show additional Groq-specific inputs | |
| if self.user_controls["selected_llm"] == 'Groq': | |
| # Get Groq model list from config file | |
| model_options = self.config.get_groq_model_options() | |
| # Dropdown to select which Groq model to use (e.g., llama-3.1-8b) | |
| self.user_controls["selected_groq_model"] = st.selectbox("Select Model", model_options) | |
| # Textbox for entering Groq API key (masked as password) | |
| self.user_controls["GROQ_API_KEY"] = st.session_state["GROQ_API_KEY"] = st.text_input( | |
| "API Key", type="password" | |
| ) | |
| # Show a warning if the API key is not entered | |
| if not self.user_controls["GROQ_API_KEY"]: | |
| st.warning("β οΈ Please enter your GROQ API key to proceed. Don't have one? Visit: https://console.groq.com/keys") | |
| # Dropdown to select which use case to run (e.g., Basic Chatbot, Chatbot With Web, AI News) | |
| self.user_controls["selected_usecase"] = st.selectbox("Select Usecases", usecase_options) | |
| # If the selected use case involves web search or news fetching, | |
| # ask for the Tavily API key (used for web search capabilities) | |
| if self.user_controls["selected_usecase"] in ["Chatbot With Web", "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" | |
| ) | |
| # Show a warning if Tavily API key is not entered | |
| if not self.user_controls["TAVILY_API_KEY"]: | |
| st.warning("β οΈ Please enter your TAVILY_API_KEY to proceed. Don't have one? Visit: https://app.tavily.com/home") | |
| # If the user selects "AI News" use case, show additional news-specific options | |
| if self.user_controls['selected_usecase'] == "AI News": | |
| st.subheader("π° AI News Explorer ") | |
| # Allow user to choose the time frame for news updates | |
| with st.sidebar: | |
| time_frame = st.selectbox( | |
| "π Select Time Frame", | |
| ["Daily", "Weekly", "Monthly"], | |
| index=0 | |
| ) | |
| # Button to trigger fetching AI news | |
| if st.button("π Fetch Latest AI News", use_container_width=True): | |
| # Mark that the fetch button was clicked and store selected time frame | |
| st.session_state.IsFetchButtonClicked = True | |
| st.session_state.timeframe = time_frame | |
| # Return all collected user input values for further processing | |
| return self.user_controls | |