import streamlit as st import os from dotenv import load_dotenv from langchain_google_genai import ChatGoogleGenerativeAI from langchain.agents import load_tools, initialize_agent, AgentType # Load environment variables load_dotenv() # Retrieve API keys from environment variables GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") SERPAPI_API_KEY = os.getenv("SERPAPI_API_KEY") # Initialize the language model llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", google_api_key=GOOGLE_API_KEY) # Load the SerpAPI tool tools = load_tools(["serpapi"], llm=llm, serpapi_api_key=SERPAPI_API_KEY) # Initialize the agent agent = initialize_agent( tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=False ) # Streamlit UI st.title("Stream line AI 💬") # User input user_question = st.text_input("Enter your question:") if st.button("Submit") and user_question: with st.spinner("Processing your question..."): try: response = agent.run(user_question) st.success(response) except Exception as e: st.error(f"An error occurred: {e}")