Spaces:
Sleeping
Sleeping
app updated
Browse files
app.py
CHANGED
@@ -1,12 +1,23 @@
|
|
1 |
-
import
|
|
|
2 |
import openai
|
|
|
|
|
3 |
from llama_index.llms.openai import OpenAI
|
4 |
-
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
|
5 |
|
6 |
-
st.set_page_config(
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
st.title("Chat with the Streamlit docs, powered by LlamaIndex π¬π¦")
|
9 |
-
st.info(
|
|
|
|
|
|
|
10 |
|
11 |
if "messages" not in st.session_state.keys(): # Initialize the chat messages history
|
12 |
st.session_state.messages = [
|
@@ -16,6 +27,7 @@ if "messages" not in st.session_state.keys(): # Initialize the chat messages hi
|
|
16 |
}
|
17 |
]
|
18 |
|
|
|
19 |
@st.cache_resource(show_spinner=False)
|
20 |
def load_data():
|
21 |
reader = SimpleDirectoryReader(input_dir="./data", recursive=True)
|
@@ -58,4 +70,4 @@ if st.session_state.messages[-1]["role"] != "assistant":
|
|
58 |
st.write_stream(response_stream.response_gen)
|
59 |
message = {"role": "assistant", "content": response_stream.response}
|
60 |
# Add response to message history
|
61 |
-
st.session_state.messages.append(message)
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
import openai
|
4 |
+
import streamlit as st
|
5 |
+
from llama_index.core import Settings, SimpleDirectoryReader, VectorStoreIndex
|
6 |
from llama_index.llms.openai import OpenAI
|
|
|
7 |
|
8 |
+
st.set_page_config(
|
9 |
+
page_title="Chat with the Streamlit docs, powered by LlamaIndex",
|
10 |
+
page_icon="π¦",
|
11 |
+
layout="centered",
|
12 |
+
initial_sidebar_state="auto",
|
13 |
+
menu_items=None,
|
14 |
+
)
|
15 |
+
openai.api_key = os.environ["OPENAI_API_KEY"]
|
16 |
st.title("Chat with the Streamlit docs, powered by LlamaIndex π¬π¦")
|
17 |
+
st.info(
|
18 |
+
"Check out the full tutorial to build this app in our [blog post](https://blog.streamlit.io/build-a-chatbot-with-custom-data-sources-powered-by-llamaindex/)",
|
19 |
+
icon="π",
|
20 |
+
)
|
21 |
|
22 |
if "messages" not in st.session_state.keys(): # Initialize the chat messages history
|
23 |
st.session_state.messages = [
|
|
|
27 |
}
|
28 |
]
|
29 |
|
30 |
+
|
31 |
@st.cache_resource(show_spinner=False)
|
32 |
def load_data():
|
33 |
reader = SimpleDirectoryReader(input_dir="./data", recursive=True)
|
|
|
70 |
st.write_stream(response_stream.response_gen)
|
71 |
message = {"role": "assistant", "content": response_stream.response}
|
72 |
# Add response to message history
|
73 |
+
st.session_state.messages.append(message)
|