Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,24 +52,6 @@ def chat_with_openai(query, vectordb, openai_api_key):
|
|
| 52 |
res = chat(messages)
|
| 53 |
return res.content
|
| 54 |
|
| 55 |
-
# # Streamlit UI
|
| 56 |
-
# st.title("Document Processing and AI Chat with LangChain")
|
| 57 |
-
|
| 58 |
-
# # Load vector database
|
| 59 |
-
# zip_file_path = "chroma_db_compressed_.zip"
|
| 60 |
-
# extract_path = "./chroma_db_extracted"
|
| 61 |
-
# vectordb = load_vector_db(zip_file_path, extract_path)
|
| 62 |
-
|
| 63 |
-
# # Query input
|
| 64 |
-
# query = st.text_input("Enter your query", "Recommend a company to work as a data scientist in the health sector")
|
| 65 |
-
|
| 66 |
-
# if st.button("Get Answer"):
|
| 67 |
-
# # Chat with OpenAI
|
| 68 |
-
# openai_api_key = st.secrets["OPENAI_API_KEY"]
|
| 69 |
-
# response = chat_with_openai(query, vectordb, openai_api_key)
|
| 70 |
-
# st.write("Response from AI:")
|
| 71 |
-
# st.write(response)
|
| 72 |
-
|
| 73 |
|
| 74 |
# Streamlit UI
|
| 75 |
st.title("Data Roles Company Finder Chatbot")
|
|
@@ -82,35 +64,93 @@ vectordb = load_vector_db(zip_file_path, extract_path)
|
|
| 82 |
|
| 83 |
# Initialize session state for chat history
|
| 84 |
if "messages" not in st.session_state:
|
| 85 |
-
st.session_state.messages = [
|
| 86 |
-
SystemMessage(content="You are a helpful assistant.")
|
| 87 |
-
]
|
| 88 |
|
| 89 |
# Display chat history
|
| 90 |
for message in st.session_state.messages:
|
| 91 |
-
|
| 92 |
-
st.
|
| 93 |
-
else:
|
| 94 |
-
st.write(f"AI: {message.content}")
|
| 95 |
|
| 96 |
# Query input
|
| 97 |
-
query = st.text_input("Enter your query", "
|
| 98 |
|
| 99 |
if st.button("Send"):
|
| 100 |
if query:
|
| 101 |
# Add user query to chat history
|
| 102 |
-
st.session_state.messages.append(
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Chat with OpenAI
|
| 105 |
openai_api_key = st.secrets["OPENAI_API_KEY"]
|
| 106 |
response = chat_with_openai(query, vectordb, openai_api_key)
|
| 107 |
|
| 108 |
# Add AI response to chat history
|
| 109 |
-
st.session_state.messages.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
| 52 |
res = chat(messages)
|
| 53 |
return res.content
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
# Streamlit UI
|
| 57 |
st.title("Data Roles Company Finder Chatbot")
|
|
|
|
| 64 |
|
| 65 |
# Initialize session state for chat history
|
| 66 |
if "messages" not in st.session_state:
|
| 67 |
+
st.session_state.messages = []
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# Display chat history
|
| 70 |
for message in st.session_state.messages:
|
| 71 |
+
with st.chat_message(message["role"]):
|
| 72 |
+
st.markdown(message["content"])
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# Query input
|
| 75 |
+
query = st.text_input("Enter your query", "")
|
| 76 |
|
| 77 |
if st.button("Send"):
|
| 78 |
if query:
|
| 79 |
# Add user query to chat history
|
| 80 |
+
st.session_state.messages.append({"role": "user", "content": query})
|
| 81 |
+
with st.chat_message("user"):
|
| 82 |
+
st.markdown(query)
|
| 83 |
|
| 84 |
# Chat with OpenAI
|
| 85 |
openai_api_key = st.secrets["OPENAI_API_KEY"]
|
| 86 |
response = chat_with_openai(query, vectordb, openai_api_key)
|
| 87 |
|
| 88 |
# Add AI response to chat history
|
| 89 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 90 |
+
with st.chat_message("assistant"):
|
| 91 |
+
st.markdown(response)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# # Streamlit UI
|
| 96 |
+
# st.title("Document Processing and AI Chat with LangChain")
|
| 97 |
+
|
| 98 |
+
# # Load vector database
|
| 99 |
+
# zip_file_path = "chroma_db_compressed_.zip"
|
| 100 |
+
# extract_path = "./chroma_db_extracted"
|
| 101 |
+
# vectordb = load_vector_db(zip_file_path, extract_path)
|
| 102 |
+
|
| 103 |
+
# # Query input
|
| 104 |
+
# query = st.text_input("Enter your query", "List three companies where I can work as a business analyst with their location and salary")
|
| 105 |
+
|
| 106 |
+
# if st.button("Get Answer"):
|
| 107 |
+
# # Chat with OpenAI
|
| 108 |
+
# openai_api_key = st.secrets["OPENAI_API_KEY"]
|
| 109 |
+
# response = chat_with_openai(query, vectordb, openai_api_key)
|
| 110 |
+
# st.write("Response from AI:")
|
| 111 |
+
# st.write(response)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
# # Streamlit UI
|
| 115 |
+
# st.title("Data Roles Company Finder Chatbot")
|
| 116 |
+
# st.write("This app helps users find companies hiring for data roles, providing information such as job title, salary estimate, job description, company rating, and more.")
|
| 117 |
+
|
| 118 |
+
# # Load vector database
|
| 119 |
+
# zip_file_path = "chroma_db_compressed_.zip"
|
| 120 |
+
# extract_path = "./chroma_db_extracted"
|
| 121 |
+
# vectordb = load_vector_db(zip_file_path, extract_path)
|
| 122 |
+
|
| 123 |
+
# # Initialize session state for chat history
|
| 124 |
+
# if "messages" not in st.session_state:
|
| 125 |
+
# st.session_state.messages = [
|
| 126 |
+
# SystemMessage(content="You are a helpful assistant.")
|
| 127 |
+
# ]
|
| 128 |
+
|
| 129 |
+
# # Display chat history
|
| 130 |
+
# for message in st.session_state.messages:
|
| 131 |
+
# if isinstance(message, HumanMessage):
|
| 132 |
+
# st.write(f"You: {message.content}")
|
| 133 |
+
# else:
|
| 134 |
+
# st.write(f"AI: {message.content}")
|
| 135 |
+
|
| 136 |
+
# # Query input
|
| 137 |
+
# query = st.text_input("Enter your query", "List three companies where I can work as a business analyst with their location and salary")
|
| 138 |
+
|
| 139 |
+
# if st.button("Send"):
|
| 140 |
+
# if query:
|
| 141 |
+
# # Add user query to chat history
|
| 142 |
+
# st.session_state.messages.append(HumanMessage(content=query))
|
| 143 |
+
|
| 144 |
+
# # Chat with OpenAI
|
| 145 |
+
# openai_api_key = st.secrets["OPENAI_API_KEY"]
|
| 146 |
+
# response = chat_with_openai(query, vectordb, openai_api_key)
|
| 147 |
+
|
| 148 |
+
# # Add AI response to chat history
|
| 149 |
+
# st.session_state.messages.append(SystemMessage(content=response))
|
| 150 |
|
| 151 |
+
# # Display chat history
|
| 152 |
+
# for message in st.session_state.messages:
|
| 153 |
+
# if isinstance(message, HumanMessage):
|
| 154 |
+
# st.write(f"You: {message.content}")
|
| 155 |
+
# else:
|
| 156 |
+
# st.write(f"AI: {message.content}")
|