lakshyaag commited on
Commit
dab89de
β€’
1 Parent(s): 1673a09

midterm: move to streamlit

Browse files
Files changed (5) hide show
  1. Dockerfile +1 -1
  2. app.py +39 -14
  3. chainlit.md +0 -5
  4. requirements.txt +1 -1
  5. 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 ["chainlit", "run", "app.py", "--port", "7860"]
 
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
- import chainlit as cl
 
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
- @cl.on_message
15
- async def main(message: cl.Message):
16
  """
17
- This function will be called every time a message is recieved from a session.
 
 
18
  """
 
19
 
20
- msg = cl.Message(content="")
 
 
 
 
 
 
 
 
 
21
 
22
- res = graph.invoke(
23
- {"question": message.content},
24
- config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
25
- )
26
 
27
- print(res)
 
28
 
29
- msg.content = res["generation"].content
30
 
31
- await msg.send()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- chainlit==1.1.302
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
- ]