Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,20 +52,65 @@ def chat_with_openai(query, vectordb, openai_api_key):
|
|
| 52 |
res = chat(messages)
|
| 53 |
return res.content
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# Streamlit UI
|
| 56 |
-
st.title("
|
|
|
|
| 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("
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|
| 76 |
+
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.")
|
| 77 |
|
| 78 |
# Load vector database
|
| 79 |
zip_file_path = "chroma_db_compressed_.zip"
|
| 80 |
extract_path = "./chroma_db_extracted"
|
| 81 |
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 |
+
if isinstance(message, HumanMessage):
|
| 92 |
+
st.write(f"You: {message.content}")
|
| 93 |
+
else:
|
| 94 |
+
st.write(f"AI: {message.content}")
|
| 95 |
+
|
| 96 |
# Query input
|
| 97 |
query = st.text_input("Enter your query", "Recommend a company to work as a data scientist in the health sector")
|
| 98 |
|
| 99 |
+
if st.button("Send"):
|
| 100 |
+
if query:
|
| 101 |
+
# Add user query to chat history
|
| 102 |
+
st.session_state.messages.append(HumanMessage(content=query))
|
| 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(SystemMessage(content=response))
|
| 110 |
+
|
| 111 |
+
# Display chat history
|
| 112 |
+
for message in st.session_state.messages:
|
| 113 |
+
if isinstance(message, HumanMessage):
|
| 114 |
+
st.write(f"You: {message.content}")
|
| 115 |
+
else:
|
| 116 |
+
st.write(f"AI: {message.content}")
|