Spaces:
Sleeping
Sleeping
initial commit
Browse files- .env +1 -0
- .gitignore +1 -0
- app.py +68 -0
- requirements.txt +6 -0
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
GROQ_API_KEY = "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"
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# *** Installing Necessary Libraries ***
|
| 2 |
+
# !pip install streamlit
|
| 3 |
+
# !pip install groq
|
| 4 |
+
# !pip install keras
|
| 5 |
+
# !pip install langchain
|
| 6 |
+
# !pip install langchain_groq
|
| 7 |
+
# !pip install dotenv
|
| 8 |
+
|
| 9 |
+
# *** Importing Necessary Packages ***
|
| 10 |
+
import streamlit as st
|
| 11 |
+
import os
|
| 12 |
+
from groq import Groq
|
| 13 |
+
import random
|
| 14 |
+
from langchain.chains import ConversationChain
|
| 15 |
+
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
|
| 16 |
+
from langchain_groq import ChatGroq
|
| 17 |
+
from langchain.prompts import PromptTemplate
|
| 18 |
+
from dotenv import load_dotenv
|
| 19 |
+
load_dotenv()
|
| 20 |
+
|
| 21 |
+
api_key = os.environ['GROQ_API_KEY'] # Retriving API Key from environment file
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def main():
|
| 25 |
+
|
| 26 |
+
st.title("Chai pe Charcha with Arghya") # Define a title for the chatbot Front End
|
| 27 |
+
|
| 28 |
+
# Add customization options to the sidebar
|
| 29 |
+
st.sidebar.title('Select an LLM') # Define a title for the chatbot Side Bar
|
| 30 |
+
model = st.sidebar.selectbox(
|
| 31 |
+
'Choose a model',
|
| 32 |
+
['mixtral-8x7b-32768', 'llama2-70b-4096', 'Gemma-7b-lt'] # Define a choices for LLM Model
|
| 33 |
+
)
|
| 34 |
+
conversational_memory_length = st.sidebar.slider('Conversational memory length:',
|
| 35 |
+
1, 10, value = 5) # Define a slider to choose the lengh of converstaion in Side Bar
|
| 36 |
+
|
| 37 |
+
memory=ConversationBufferWindowMemory(k=conversational_memory_length) # Store the user chosen length as memory for future use
|
| 38 |
+
|
| 39 |
+
user_question = st.text_area("What's in your mind..") # Define a prompt for question area
|
| 40 |
+
|
| 41 |
+
# session state variable
|
| 42 |
+
if 'chat_history' not in st.session_state:
|
| 43 |
+
st.session_state.chat_history=[]
|
| 44 |
+
else:
|
| 45 |
+
for message in st.session_state.chat_history:
|
| 46 |
+
memory.save_context({'input':message['human']},{'output':message['AI']}) # Storing the context of the conversation
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# Initialize Groq Langchain chat object and conversation
|
| 50 |
+
groq_chat = ChatGroq(
|
| 51 |
+
groq_api_key = api_key,
|
| 52 |
+
model_name=model # Initializing the Groq ChatBot
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
conversation = ConversationChain(
|
| 56 |
+
llm=groq_chat,
|
| 57 |
+
memory=memory # Initializing the conversation chain
|
| 58 |
+
)
|
| 59 |
+
if st.button("Submit & Process"):
|
| 60 |
+
if user_question:
|
| 61 |
+
with st.spinner("Processing..."):
|
| 62 |
+
response = conversation(user_question) # Generating response for User's Question
|
| 63 |
+
message = {'human':user_question,'AI':response['response']}
|
| 64 |
+
st.session_state.chat_history.append(message) # Appending the QnA to chat history
|
| 65 |
+
st.write("Chatbot:", response['response']) # Writing back the response in Front End
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
groq
|
| 3 |
+
keras
|
| 4 |
+
langchain
|
| 5 |
+
langchain_groq
|
| 6 |
+
dotenv
|