ByteBrewer commited on
Commit
2ad2e9e
·
verified ·
1 Parent(s): 045bfaa

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Conversational Q&A Chatbot
2
+ import streamlit as st
3
+
4
+ from langchain.schema import HumanMessage,SystemMessage,AIMessage
5
+ from langchain_community.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
+
14
+ chat=ChatOpenAI(temperature=0.5)
15
+
16
+ if 'flowmessages' not in st.session_state:
17
+ st.session_state['flowmessages']=[
18
+ SystemMessage(content="You are a AI assitant")
19
+ ]
20
+
21
+ ## Function to load OpenAI model and get respones
22
+
23
+ def get_chatmodel_response(question):
24
+
25
+ st.session_state['flowmessages'].append(HumanMessage(content=question))
26
+ answer=chat(st.session_state['flowmessages'])
27
+ st.session_state['flowmessages'].append(AIMessage(content=answer.content))
28
+ return answer.content
29
+
30
+ input=st.text_input("Input: ",key="input")
31
+ response=get_chatmodel_response(input)
32
+
33
+ submit=st.button("Ask the question")
34
+
35
+ ## If ask button is clicked
36
+
37
+ if submit:
38
+ st.subheader("The Response is")
39
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ openai
2
+ langchain
3
+ huggingface_hub
4
+ python-dotenv
5
+ streamlit