Your Name commited on
Commit
a058e02
1 Parent(s): 4a6f9a4
Files changed (1) hide show
  1. app.py +43 -11
app.py CHANGED
@@ -1,13 +1,45 @@
1
- """
2
- # My first app
3
- Here's our first attempt at using data to create a table:
4
- """
5
-
6
  import streamlit as st
7
- import pandas as pd
8
- df = pd.DataFrame({
9
- 'first column': [1, 2, 3, 4],
10
- 'second column': [10, 20, 30, 40]
11
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- df
 
 
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
+ import os
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, Nice to meet you", key="input")
30
+ return input_text
31
+
32
+
33
+
34
+
35
+ if st.session_state["generated"]:
36
+ for i in range(len(st.session_state["generated"]) - 1, -1, -1):
37
+ message(st.session_state["past"][i], is_user=True, key=str(i) + "_user")
38
+ message(st.session_state["generated"][i], key=str(i))
39
+
40
+ user_input = get_text()
41
+ if user_input:
42
+ output = chain.run(input=user_input)
43
 
44
+ st.session_state.past.append(user_input)
45
+ st.session_state.generated.append(output)