Your Name commited on
Commit
eab05da
1 Parent(s): 006aa2c
Files changed (2) hide show
  1. main.py +45 -0
  2. requirements.txt +4 -0
main.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Python file to serve as the frontend"""
2
+ import streamlit as st
3
+ from streamlit_chat import message
4
+
5
+ from langchain.chains import ConversationChain
6
+ from langchain.llms import OpenAI
7
+
8
+
9
+ def load_chain():
10
+ """Logic for loading the chain you want to use should go here."""
11
+ llm = OpenAI(temperature=0)
12
+ chain = ConversationChain(llm=llm)
13
+ return chain
14
+
15
+ chain = load_chain()
16
+
17
+ # From here down is all the StreamLit UI.
18
+ st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
19
+ st.header("LangChain Demo")
20
+
21
+ if "generated" not in st.session_state:
22
+ st.session_state["generated"] = []
23
+
24
+ if "past" not in st.session_state:
25
+ st.session_state["past"] = []
26
+
27
+
28
+ def get_text():
29
+ input_text = st.text_input("You: ", "Hello, how are you?", key="input")
30
+ return input_text
31
+
32
+
33
+ user_input = get_text()
34
+
35
+ if user_input:
36
+ output = chain.run(input=user_input)
37
+
38
+ st.session_state.past.append(user_input)
39
+ st.session_state.generated.append(output)
40
+
41
+ if st.session_state["generated"]:
42
+
43
+ for i in range(len(st.session_state["generated"]) - 1, -1, -1):
44
+ message(st.session_state["generated"][i], key=str(i))
45
+ message(st.session_state["past"][i], is_user=True, key=str(i) + "_user")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ streamlit
4
+ streamlit-chat