praveenku32k commited on
Commit
a240028
1 Parent(s): 172abd6

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +55 -0
  2. env-sample.txt +1 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+
4
+
5
+ from langchain.chat_models import ChatOpenAI
6
+ from langchain.schema import (
7
+ AIMessage,
8
+ HumanMessage,
9
+ SystemMessage
10
+ )
11
+
12
+ # From here down is all the StreamLit UI.
13
+ st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
14
+ st.header("Hey, I'm your Chat GPT")
15
+
16
+
17
+
18
+ if "sessionMessages" not in st.session_state:
19
+ st.session_state.sessionMessages = [
20
+ SystemMessage(content="You are a helpful assistant.")
21
+ ]
22
+
23
+
24
+
25
+ def load_answer(question):
26
+
27
+ st.session_state.sessionMessages.append(HumanMessage(content=question))
28
+
29
+ assistant_answer = chat(st.session_state.sessionMessages )
30
+
31
+ st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
32
+
33
+ return assistant_answer.content
34
+
35
+
36
+ def get_text():
37
+ input_text = st.text_input("You: ", key= input)
38
+ return input_text
39
+
40
+
41
+ chat = ChatOpenAI(temperature=0)
42
+
43
+
44
+
45
+
46
+ user_input=get_text()
47
+ submit = st.button('Generate')
48
+
49
+ if submit:
50
+
51
+ response = load_answer(user_input)
52
+ st.subheader("Answer:")
53
+
54
+ st.write(response,key= 1)
55
+
env-sample.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY=""
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ langchain
3
+ openai
4
+ streamlit-chat
5
+ python-dotenv