-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatbot.py
More file actions
44 lines (31 loc) · 1.24 KB
/
Chatbot.py
File metadata and controls
44 lines (31 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## Conversational Q&A Chatbot
from dotenv import load_dotenv
load_dotenv()
import os
# Setting the Environment Variables
os.environ['OPENAI_API_KEY'] = os.getenv('openai_api_key')
import streamlit as st
from langchain.schema import HumanMessage,SystemMessage,AIMessage
from langchain_openai import ChatOpenAI
## Streamlit UI
st.set_page_config(page_title="Conversational Q&A Chatbot")
st.header("I love Commedy, Let's have a Chat to understand my humour")
chat=ChatOpenAI(temperature=0.5)
if 'flowmessages' not in st.session_state:
st.session_state['flowmessages']=[
SystemMessage(content="Yor are a comedian AI assitant")
]
## Function to load OpenAI model and get respones
def get_chatmodel_response(question):
st.session_state['flowmessages'].append(HumanMessage(content=question))
answer=chat(st.session_state['flowmessages'])
st.session_state['flowmessages'].append(AIMessage(content=answer.content))
return answer.content
input=st.text_input("Please type queries: ",key="input")
response=get_chatmodel_response(input)
# Button that triggers the call
submit=st.button("Ask")
## If ask button is clicked
if submit:
st.subheader("The Response is")
st.write(response)