sunithalv commited on
Commit
ca42192
·
1 Parent(s): dbf6e32

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Conversational Q&A Chatbot
2
+ import streamlit as st
3
+
4
+ from langchain.schema import HumanMessage,SystemMessage,AIMessage
5
+ from langchain.chat_models import ChatOpenAI
6
+
7
+ ## Streamlit UI
8
+ st.set_page_config(page_title="Conversational Q&A Chatbot")
9
+ st.header("Hey, Let's Chat")
10
+
11
+ # from dotenv import load_dotenv
12
+ # load_dotenv()
13
+ import os
14
+
15
+ chat=ChatOpenAI(temperature=0.5)
16
+
17
+ #Create a session key flowmessages with System Message
18
+ if 'flowmessages' not in st.session_state:
19
+ st.session_state['flowmessages']=[
20
+ SystemMessage(content="You are a comedian AI assitant")
21
+ ]
22
+
23
+ ## Function to load OpenAI model and get respones
24
+
25
+ def get_chatmodel_response(question):
26
+ #Append the question to session key
27
+ st.session_state['flowmessages'].append(HumanMessage(content=question))
28
+ #Send the query to the ChatOpenAI
29
+ answer=chat(st.session_state['flowmessages'])
30
+ #Append the answer to the session state
31
+ st.session_state['flowmessages'].append(AIMessage(content=answer.content))
32
+ return answer.content
33
+
34
+ input=st.text_input("Input: ",key="input")
35
+ response=get_chatmodel_response(input)
36
+
37
+ submit=st.button("Ask the question")
38
+
39
+ ## If ask button is clicked
40
+
41
+ if submit:
42
+ st.subheader("The Response is")
43
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ huggingface_hub
4
+ python-dotenv
5
+ streamlit