Genius0 commited on
Commit
457dd7b
1 Parent(s): b790382

Upload 2 files

Browse files
Files changed (2) hide show
  1. app1.py +52 -0
  2. requirements.txt +5 -0
app1.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##Conversational Q&A Chatbot
2
+
3
+ import streamlit as st
4
+ from langchain.schema import HumanMessage,SystemMessage,AIMessage
5
+ from langchain.chat_models import ChatOpenAI
6
+ import os
7
+
8
+
9
+ ##Streamlit UI
10
+ st.set_page_config(page_title="Conversational Q&A Chatbot")
11
+ st.header("Hey!! lets do code")
12
+
13
+ from dotenv import load_dotenv
14
+ load_dotenv()
15
+
16
+
17
+
18
+ chat = ChatOpenAI(temperature=0.6,openai_api_key=os.getenv('OPEN_API_KEY'))
19
+
20
+ if 'flowmesages' not in st.session_state:
21
+ st.session_state['flowmessages']=[
22
+ SystemMessage(content="you are a comedian AI assistent")
23
+ ]
24
+
25
+ ##function to load OpenAI model and get responses
26
+
27
+ def get_chatmodel_response(question):
28
+
29
+ st.session_state['flowmessages'].append(HumanMessage(content=question))
30
+ answer=chat(st.session_state['flowmessages'])
31
+ st.session_state['flowmessages'].append(AIMessage(content=answer.content))
32
+
33
+ return answer.content
34
+
35
+
36
+
37
+ input = st.text_input("Input: ",key= "input")
38
+ submit= st.button("Ask a question")
39
+
40
+
41
+ if submit:
42
+ response = get_chatmodel_response(input)
43
+ st.subheader("The response is")
44
+ st.write(response)
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ huggingface_hub
4
+ python-dotenv
5
+ streamlit