suzall commited on
Commit
c49f0e4
·
verified ·
1 Parent(s): 8704860

Create app.py

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