midterm: move to streamlit
Browse files- Dockerfile +1 -1
- app.py +39 -14
- chainlit.md +0 -5
- requirements.txt +1 -1
- starters.py +0 -19
Dockerfile
CHANGED
@@ -14,4 +14,4 @@ RUN pip install -r $HOME/app/requirements.txt
|
|
14 |
COPY --chown=user . $HOME/app
|
15 |
RUN chown user -R ${HOME}/app/
|
16 |
|
17 |
-
CMD ["
|
|
|
14 |
COPY --chown=user . $HOME/app
|
15 |
RUN chown user -R ${HOME}/app/
|
16 |
|
17 |
+
CMD ["streamlit", "run", "app.py", "--server.port", "7860"]
|
app.py
CHANGED
@@ -1,31 +1,56 @@
|
|
1 |
import os
|
2 |
-
|
|
|
3 |
from dotenv import load_dotenv
|
4 |
from graph import create_graph
|
5 |
-
from langchain_core.runnables import RunnableConfig
|
6 |
-
from starters import set_starters
|
7 |
|
8 |
load_dotenv()
|
9 |
|
10 |
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
|
11 |
graph = create_graph()
|
12 |
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
async def main(message: cl.Message):
|
16 |
"""
|
17 |
-
This
|
|
|
|
|
18 |
"""
|
|
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
res = graph.invoke(
|
23 |
-
{"question": message.content},
|
24 |
-
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
|
25 |
-
)
|
26 |
|
27 |
-
|
|
|
28 |
|
29 |
-
|
30 |
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
from dotenv import load_dotenv
|
5 |
from graph import create_graph
|
|
|
|
|
6 |
|
7 |
load_dotenv()
|
8 |
|
9 |
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
|
10 |
graph = create_graph()
|
11 |
|
12 |
+
st.set_page_config(page_title="Airbnb 10-Q Chatbot", layout="wide", page_icon="ποΈ")
|
13 |
+
|
14 |
+
st.title("Airbnb 10-Q Chatbot")
|
15 |
|
16 |
+
st.markdown(
|
|
|
17 |
"""
|
18 |
+
### This chatbot is designed to answer questions about Airbnb's 10-Q financial statement for the quarter ended March 31, 2024.
|
19 |
+
|
20 |
+
It uses corrective RAG as the architecture to retrieve information based on the user's input, grading the relevance of the retrieved documents, and optionally querying Wikipedia for additional information, if necessary.
|
21 |
"""
|
22 |
+
)
|
23 |
|
24 |
+
if "messages" not in st.session_state:
|
25 |
+
st.session_state.messages = [
|
26 |
+
{
|
27 |
+
"role": "Assistant",
|
28 |
+
"content": "Hello! I'm here to help you with Airbnb's 10-Q. Feel free to ask me anything.",
|
29 |
+
}
|
30 |
+
]
|
31 |
+
|
32 |
+
for message in st.session_state.messages:
|
33 |
+
st.chat_message(message["role"]).write(message["content"])
|
34 |
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
if prompt := st.chat_input("Ask about Airbnb's 10-Q"):
|
37 |
+
st.chat_message("User").write(prompt)
|
38 |
|
39 |
+
st.session_state.messages.append({"role": "User", "content": prompt})
|
40 |
|
41 |
+
with st.chat_message("Assistant"):
|
42 |
+
with st.status("Thinking...", expanded=True) as status:
|
43 |
+
for event in graph.stream(
|
44 |
+
{
|
45 |
+
"question": prompt,
|
46 |
+
},
|
47 |
+
):
|
48 |
+
for key, value in event.items():
|
49 |
+
if key == "generate":
|
50 |
+
st.write(value["generation"].content)
|
51 |
+
|
52 |
+
status.update(label="Done!", expanded=True, state="complete")
|
53 |
+
|
54 |
+
st.session_state.messages.append(
|
55 |
+
{"role": "Assistant", "content": event["generate"]["generation"].content}
|
56 |
+
)
|
chainlit.md
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
# Airbnb 10-Q Chatbot
|
2 |
-
|
3 |
-
This chatbot is designed to answer questions about Airbnb's 10-Q financial statement for the quarter ended March 31, 2024.
|
4 |
-
|
5 |
-
It uses corrective RAG as the architecture to retrieve information based on the user's input, grading the relevance of the retrieved documents, and optionally querying Wikipedia for additional information, if necessary.
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
langchain==0.2.5
|
3 |
langchain_core==0.2.9
|
4 |
langchain_community==0.2.5
|
|
|
1 |
+
streamlit=1.36.0
|
2 |
langchain==0.2.5
|
3 |
langchain_core==0.2.9
|
4 |
langchain_community==0.2.5
|
starters.py
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
import chainlit as cl
|
2 |
-
|
3 |
-
|
4 |
-
@cl.set_starters
|
5 |
-
async def set_starters():
|
6 |
-
return [
|
7 |
-
cl.Starter(
|
8 |
-
label="ποΈ What is the business of Airbnb",
|
9 |
-
message="What is Airbnb's 'Description of Business'?",
|
10 |
-
),
|
11 |
-
cl.Starter(
|
12 |
-
label="π΅ Cash and Cash Equivalents",
|
13 |
-
message="What was the total value of 'Cash and cash equivalents' as of December 31, 2023?",
|
14 |
-
),
|
15 |
-
cl.Starter(
|
16 |
-
label="ποΈ Maximum allowed sales",
|
17 |
-
message="What is the 'maximum number of shares to be sold under the 10b5-1 Trading plan' by Brian Chesky?",
|
18 |
-
),
|
19 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|