Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,6 +34,7 @@ with st.sidebar:
|
|
| 34 |
add_vertical_space(3) # Add more vertical space between text blocks
|
| 35 |
st.write('Made with ❤️ by Anne')
|
| 36 |
|
|
|
|
| 37 |
openai_api_key = st.text_input("Enter your OpenAI API key:")
|
| 38 |
|
| 39 |
def load_pdf(file_path, openai_api_key):
|
|
@@ -85,7 +86,6 @@ def main():
|
|
| 85 |
# Pass the openai_api_key parameter here
|
| 86 |
VectorStore = load_pdf(pdf, openai_api_key)
|
| 87 |
|
| 88 |
-
|
| 89 |
display_chat_history(st.session_state['chat_history'])
|
| 90 |
|
| 91 |
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
|
@@ -105,8 +105,8 @@ def main():
|
|
| 105 |
loading_message = st.empty()
|
| 106 |
loading_message.text('Bot is thinking...')
|
| 107 |
|
| 108 |
-
VectorStore = load_pdf(pdf)
|
| 109 |
-
chain = load_chatbot()
|
| 110 |
docs = VectorStore.similarity_search(query=st.session_state['processing_input'], k=3)
|
| 111 |
with get_openai_callback() as cb:
|
| 112 |
response = chain.run(input_documents=docs, question=st.session_state['processing_input'])
|
|
@@ -120,11 +120,5 @@ def main():
|
|
| 120 |
# Mark all messages as old after displaying
|
| 121 |
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
| 122 |
|
| 123 |
-
|
| 124 |
-
def display_chat_history(chat_history):
|
| 125 |
-
for chat in chat_history:
|
| 126 |
-
background_color = "#FFA07A" if chat[2] == "new" else "#acf" if chat[0] == "User" else "#caf"
|
| 127 |
-
st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
|
| 128 |
-
|
| 129 |
if __name__ == "__main__":
|
| 130 |
main()
|
|
|
|
| 34 |
add_vertical_space(3) # Add more vertical space between text blocks
|
| 35 |
st.write('Made with ❤️ by Anne')
|
| 36 |
|
| 37 |
+
# User input for the OpenAI API key
|
| 38 |
openai_api_key = st.text_input("Enter your OpenAI API key:")
|
| 39 |
|
| 40 |
def load_pdf(file_path, openai_api_key):
|
|
|
|
| 86 |
# Pass the openai_api_key parameter here
|
| 87 |
VectorStore = load_pdf(pdf, openai_api_key)
|
| 88 |
|
|
|
|
| 89 |
display_chat_history(st.session_state['chat_history'])
|
| 90 |
|
| 91 |
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
|
|
|
| 105 |
loading_message = st.empty()
|
| 106 |
loading_message.text('Bot is thinking...')
|
| 107 |
|
| 108 |
+
VectorStore = load_pdf(pdf, openai_api_key) # Pass the API key here
|
| 109 |
+
chain = load_chatbot(openai_api_key) # Pass the API key here
|
| 110 |
docs = VectorStore.similarity_search(query=st.session_state['processing_input'], k=3)
|
| 111 |
with get_openai_callback() as cb:
|
| 112 |
response = chain.run(input_documents=docs, question=st.session_state['processing_input'])
|
|
|
|
| 120 |
# Mark all messages as old after displaying
|
| 121 |
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
if __name__ == "__main__":
|
| 124 |
main()
|