Spaces:
Sleeping
Sleeping
| # Q&A ChatBot using Gemini AI | |
| import streamlit as st | |
| import os | |
| from dotenv import load_dotenv | |
| from langchain_google_genai import ChatGoogleGenerativeAI | |
| # Load environment variables | |
| load_dotenv() | |
| GOOGLE_API_KEY = os.getenv("API_KEY") | |
| # Ensure API key is available | |
| if not GOOGLE_API_KEY: | |
| st.error("Google API Key is missing! Set it in your .env file.") | |
| st.stop() | |
| # Function to load Gemini model and get response | |
| def get_gemini_response(question): | |
| llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro", google_api_key=GOOGLE_API_KEY) | |
| response = llm.invoke(question) | |
| return response.content | |
| # Initialize Streamlit app | |
| st.set_page_config(page_title="Q&A Demo") | |
| st.header("Langchain Application with Gemini AI") | |
| # User input | |
| user_input = st.text_input("Input:", key="input") | |
| # Button to submit the question | |
| submit = st.button("Ask the question") | |
| # If submit button is clicked | |
| if submit and user_input: | |
| response = get_gemini_response(user_input) | |
| st.subheader("The Response is:") | |
| st.write(response) | |