Your Name
commited on
Commit
•
a058e02
1
Parent(s):
4a6f9a4
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 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
|
|
|
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)
|