Upload 3 files
Browse files- .env +1 -0
- app.py +59 -0
- requirements.txt +3 -0
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
GOOGLE_API_KEY = "AIzaSyCsBCJtPSrc0If5NXwzGXPK-sRmtYR0Vc0"
|
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Load environment variables
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
# Initialize the language model
|
| 10 |
+
llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro",
|
| 11 |
+
temperature=0.6,
|
| 12 |
+
google_api_key=os.getenv("GOOGLE_API_KEY"))
|
| 13 |
+
|
| 14 |
+
# Set Streamlit page configuration
|
| 15 |
+
st.set_page_config(page_title="Q&A Chatbot", page_icon="🤖", layout="centered", initial_sidebar_state="auto")
|
| 16 |
+
|
| 17 |
+
# Main application interface
|
| 18 |
+
st.header("Quest Bot")
|
| 19 |
+
|
| 20 |
+
# Function to handle user input and model response
|
| 21 |
+
def chat(input_question):
|
| 22 |
+
try:
|
| 23 |
+
# Get response from the model
|
| 24 |
+
with st.spinner("getting response..."):
|
| 25 |
+
response = llm.invoke(input_question)
|
| 26 |
+
return response.content
|
| 27 |
+
except ValueError as ve:
|
| 28 |
+
st.error(f"ValueError: {str(ve)}")
|
| 29 |
+
except Exception as e:
|
| 30 |
+
st.error(f"Error: {str(e)}")
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
# Initialize conversation history
|
| 34 |
+
conversation = []
|
| 35 |
+
|
| 36 |
+
# User input for the question
|
| 37 |
+
input_question = st.text_input("Input your question here: ")
|
| 38 |
+
|
| 39 |
+
# Button to submit the question
|
| 40 |
+
if st.button("Ask"):
|
| 41 |
+
if input_question:
|
| 42 |
+
st.spinner("getting response...")
|
| 43 |
+
# Add user input to conversation history
|
| 44 |
+
conversation.append(f"You: {input_question}")
|
| 45 |
+
|
| 46 |
+
# Get response from the model
|
| 47 |
+
response = chat(input_question)
|
| 48 |
+
|
| 49 |
+
if response:
|
| 50 |
+
# Add model response to conversation history
|
| 51 |
+
conversation.append(f"Quest Bot: {response}")
|
| 52 |
+
|
| 53 |
+
# Display conversation history
|
| 54 |
+
st.subheader("Conversation")
|
| 55 |
+
for message in conversation:
|
| 56 |
+
st.write(message)
|
| 57 |
+
else:
|
| 58 |
+
# Show a warning if no question is input
|
| 59 |
+
st.warning("Please input a question.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
google-generativeai
|
| 2 |
+
langchain
|
| 3 |
+
langchain_community
|