AjayKr09 commited on
Commit
f74b435
·
verified ·
1 Parent(s): 0e093ed

Upload 3 files

Browse files
AI_Chat_Bot.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.title("AI Chat Bot Dashboard")
4
+
5
+ st.header('Interactive Chatbot')
6
+
7
+ st.write('''An interactive chatbot is designed to engage in dynamic, back-and-forth conversations with users.
8
+ These chatbots can understand and retain context from previous interactions, making their responses more
9
+ relevant and coherent as the conversation progresses. Interactive chatbots often use advanced natural language
10
+ processing (NLP) techniques and memory management to provide a more human-like experience. They are commonly used
11
+ in applications where ongoing interaction and context awareness are crucial, such as customer support, virtual
12
+ assistants, and personalized recommendations.''')
13
+
14
+ st.header('Non-Interactive Chatbot')
15
+
16
+ st.write('''A non-interactive chatbot, on the other hand, is designed for more straightforward, single-turn interactions.
17
+ These chatbots do not retain context from previous interactions, meaning each user query is treated independently.
18
+ Non-interactive chatbots are typically used for simple, transactional tasks where context is not required. They are
19
+ easier to develop and deploy and are suitable for scenarios where the interaction is brief and to the point.''')
pages/1_Interactive Chat Bot.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from langchain_core.prompts import ChatPromptTemplate
4
+ from langchain_google_genai import ChatGoogleGenerativeAI
5
+ from langchain_core.prompts import MessagesPlaceholder
6
+ from langchain.memory import ConversationBufferWindowMemory
7
+ from operator import itemgetter
8
+ from langchain_core.runnables import RunnableLambda, RunnablePassthrough
9
+
10
+ # Set the API key for Google Generative AI
11
+ os.environ['GOOGLE_API_KEY'] = 'AIzaSyBHPIIk4-BOgXvnQ2_o6c2wTGpY2ByRIDs'
12
+
13
+ # Initialize the Google Generative AI model
14
+ model_gemini = ChatGoogleGenerativeAI(model='gemini-pro', temperature=0, max_output_tokens=500, convert_system_message_to_human=True)
15
+
16
+ # Define the prompt
17
+ prompt = ChatPromptTemplate.from_messages(
18
+ [
19
+ ('system', 'you are a good assistant.'),
20
+ MessagesPlaceholder(variable_name='history'),
21
+ ("human", "{input}")
22
+ ]
23
+ )
24
+
25
+ # Initialize memory in session state
26
+ if 'memory' not in st.session_state:
27
+ st.session_state.memory = ConversationBufferWindowMemory(k=10, return_messages=True)
28
+
29
+ # Define the chain
30
+ chain = (RunnablePassthrough.assign(history=RunnableLambda(st.session_state.memory.load_memory_variables) | itemgetter("history")) |
31
+ prompt | model_gemini)
32
+
33
+ # Streamlit app
34
+ st.title("Interactive Chatbot")
35
+
36
+ # Initialize session state for user input
37
+ if 'user_input' not in st.session_state:
38
+ st.session_state.user_input = ""
39
+
40
+ # Input from user
41
+ user_input = st.text_area("User: ", st.session_state.user_input, height=100)
42
+
43
+ if st.button("Submit"):
44
+ response = chain.invoke({"input": user_input})
45
+ st.write(f"Assistant: {response.content}")
46
+ st.session_state.memory.save_context({"input": user_input}, {"output": response.content})
47
+ st.session_state.user_input = "" # Clear the input box
48
+
49
+ # Display chat history
50
+ if st.checkbox("Show Chat History"):
51
+ chat_history = st.session_state.memory.load_memory_variables({})
52
+ st.write(chat_history)
pages/2_Non-Interactive Chat Bot.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from langchain_google_genai import ChatGoogleGenerativeAI
4
+ from langchain_core.prompts import ChatPromptTemplate
5
+
6
+ # Set GOOGLE_API_KEY
7
+ os.environ['GOOGLE_API_KEY'] = 'AIzaSyBHPIIk4-BOgXvnQ2_o6c2wTGpY2ByRIDs'
8
+
9
+ st.title("Non-Interactive Chat Bot")
10
+
11
+ model_gemini = ChatGoogleGenerativeAI(
12
+ model='gemini-pro',
13
+ temperature=0,
14
+ max_output_tokens=500,
15
+ convert_system_message_to_human=True
16
+ )
17
+
18
+ # Assuming model_gemini is defined correctly elsewhere
19
+ prompt = ChatPromptTemplate.from_template("{content}")
20
+ chain = prompt | model_gemini
21
+
22
+ input_text = st.text_area('Ask your Question :', height=100)
23
+
24
+ # Add a button to trigger the chatbot response
25
+ if st.button('Submit'):
26
+ # Invoke the chain with input text
27
+ response = chain.invoke({'content': input_text})
28
+
29
+ # Display response on the Streamlit web interface
30
+ st.write(response.content)