from dotenv import load_dotenv import streamlit as st import os import google.generativeai as genai # Load the environment variables load_dotenv() # Configure the API key genai.configure(api_key=os.getenv("Google_api_key")) # Initialize the model model = genai.GenerativeModel('gemini-pro') # Function to load gemini model and response def load_gemini_model(question): response = model.generate_content(question) return response.text # Set up the Streamlit application st.set_page_config(page_title="Question Answering Bot with Gemini model", page_icon="🤖", layout="centered", initial_sidebar_state="auto") # Set the header as Gemini pro application st.header("Gemini pro application") # Initialize the chat history chat_history = [] # Set the input field input = st.text_input("input:", key="input") submit = st.button("ASK a QUESTION") # When the submit button is clicked if submit: response = load_gemini_model(input) # Append the question and answer to the chat history chat_history.append({"user": input, "bot": response}) # Display the chat history for chat in chat_history: st.subheader("User:") st.write(chat["user"]) st.subheader("Bot:") st.write(chat["bot"])