Spaces:
Configuration error
Configuration error
Eric B commited on
Commit ·
2c2416e
1
Parent(s): 2a4dd45
new
Browse files- README.md +0 -13
- app.py +62 -23
- favicon.ico +0 -0
- property-icon.ico +0 -0
- utils/privacy_policy.txt +1 -4
README.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Hudbot
|
| 3 |
-
emoji: 📉
|
| 4 |
-
colorFrom: yellow
|
| 5 |
-
colorTo: indigo
|
| 6 |
-
sdk: streamlit
|
| 7 |
-
sdk_version: 1.33.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: other
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -15,17 +15,53 @@ pinecone_index_name = st.secrets["PINECONE_INDEX_NAME"]
|
|
| 15 |
streamlit_api_key = st.secrets["STREAMLIT_API_KEY"]
|
| 16 |
|
| 17 |
|
| 18 |
-
system_prompt = """<system_prompt>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
questions = [
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
"
|
| 24 |
-
"
|
| 25 |
-
"
|
|
|
|
| 26 |
"List the PDF source pages and their URLS for the previous chat response from Assistant. List the full exact URLs from the source data.",
|
| 27 |
-
"
|
| 28 |
-
"Draft a formal business email to the person discussed in the chat based on the context provided in the chat. Omit any initial greetings or pleasantries. Use a colon after the \"Dear\" part.",
|
| 29 |
"""Write article about the subject in the following format:
|
| 30 |
<article_format> ## Engaging Article Title
|
| 31 |
|
|
@@ -51,13 +87,15 @@ questions = [
|
|
| 51 |
|
| 52 |
|
| 53 |
about = """
|
| 54 |
-
- This app is designed to help you find information about
|
|
|
|
| 55 |
- Enter your question in the chat box on the right.
|
|
|
|
| 56 |
- Choose how many pages of "Results" you would like to get from the knowledge base and added to the AI prompt. Increase the number to extract more information from the knowledge base.
|
| 57 |
- After the first prompt, choose whether you want another knowledge base search for the next prompt using the button below.
|
| 58 |
- The PDF pages from the knowledge base are published online and citable. Each PDF page has a link at the bottom going directly the the PDF source page so it can be seen in context.
|
| 59 |
- This app works best on desktop browsers and is not yet optimized for mobile devices.
|
| 60 |
-
-
|
| 61 |
"""
|
| 62 |
|
| 63 |
def check_password():
|
|
@@ -77,7 +115,7 @@ def check_password():
|
|
| 77 |
|
| 78 |
# Show input for password.
|
| 79 |
st.text_input(
|
| 80 |
-
"Password for
|
| 81 |
)
|
| 82 |
if "password_correct" in st.session_state:
|
| 83 |
st.error("😕 Password incorrect")
|
|
@@ -91,8 +129,8 @@ def check_password():
|
|
| 91 |
|
| 92 |
|
| 93 |
st.set_page_config(
|
| 94 |
-
page_title="
|
| 95 |
-
page_icon="
|
| 96 |
layout="wide",
|
| 97 |
initial_sidebar_state="auto"
|
| 98 |
)
|
|
@@ -172,7 +210,7 @@ def clean_text(text):
|
|
| 172 |
cleaned_text = text_without_tags.strip()
|
| 173 |
return cleaned_text
|
| 174 |
|
| 175 |
-
def truncate_prompt_last_tokens(prompt, max_tokens=
|
| 176 |
encoding = tiktoken.get_encoding("cl100k_base")
|
| 177 |
encoded_prompt = encoding.encode(prompt)
|
| 178 |
|
|
@@ -193,7 +231,7 @@ def generate_response(user_input):
|
|
| 193 |
chain = prompt | chat
|
| 194 |
try:
|
| 195 |
# Truncate the prompt to the last history and user query
|
| 196 |
-
truncated_prompt = truncate_prompt_last_tokens("\n".join([f"{role}: {msg}" for role, msg in st.session_state.messages]), max_tokens=
|
| 197 |
|
| 198 |
for chunk in chain.stream({"text": truncated_prompt}):
|
| 199 |
content = chunk.content
|
|
@@ -207,7 +245,7 @@ def generate_response(user_input):
|
|
| 207 |
except Exception as e:
|
| 208 |
# Handle the exception
|
| 209 |
error_message = f"An error occurred while generating the response: {str(e)}"
|
| 210 |
-
message = f"
|
| 211 |
level = "ERROR"
|
| 212 |
log_to_firestore("docmind-421208", message, level)
|
| 213 |
yield error_message
|
|
@@ -237,7 +275,8 @@ if "messages" not in st.session_state:
|
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
-
st.title("
|
|
|
|
| 241 |
#display questions
|
| 242 |
|
| 243 |
# st.markdown("---\n## Chat:")
|
|
@@ -248,7 +287,7 @@ with st.sidebar:
|
|
| 248 |
# st.switch_page("streamlit_app_fb.py")
|
| 249 |
# if st.button("Phrase Search"):
|
| 250 |
# st.switch_page("pages/search_database_streamlit.py")
|
| 251 |
-
st.write("Welcome to the
|
| 252 |
with st.expander("About"):
|
| 253 |
st.markdown(about)
|
| 254 |
with st.expander("Example Prompts"):
|
|
@@ -274,9 +313,9 @@ system = system_prompt
|
|
| 274 |
human = "{text}"
|
| 275 |
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])
|
| 276 |
|
| 277 |
-
if user_prompt := st.chat_input("
|
| 278 |
original_user_prompt = user_prompt
|
| 279 |
-
message = f"
|
| 280 |
level = "INFO"
|
| 281 |
log_to_firestore("docmind-421208", message, level)
|
| 282 |
if st.session_state['query_pinecone_toggle']:
|
|
@@ -289,7 +328,7 @@ if user_prompt := st.chat_input("What can I help you with about HUD?"):
|
|
| 289 |
with st.spinner("Generating response..."):
|
| 290 |
try:
|
| 291 |
response = st.write_stream(generate_response(user_prompt))
|
| 292 |
-
message = f"
|
| 293 |
# print(message)
|
| 294 |
level = "INFO"
|
| 295 |
log_to_firestore("docmind-421208", message, level)
|
|
@@ -298,7 +337,7 @@ if user_prompt := st.chat_input("What can I help you with about HUD?"):
|
|
| 298 |
except Exception as e:
|
| 299 |
error_message = f"An error occurred while generating the response: {str(e)}"
|
| 300 |
st.error(error_message)
|
| 301 |
-
message = f"
|
| 302 |
level = "ERROR"
|
| 303 |
log_to_firestore("docmind-421208", message, level)
|
| 304 |
response = ""
|
|
@@ -322,4 +361,4 @@ with st.sidebar:
|
|
| 322 |
st.markdown("<span style='color: green;'>☑<sup><sub> Knowledge base will be queried for the next message</sub></sup></span>", unsafe_allow_html=True)
|
| 323 |
else:
|
| 324 |
st.markdown("<span style='color:#8B8000;'>☐<sup><sub> Knowledge base will NOT be queried for the next message</sub></sup></span>", unsafe_allow_html=True)
|
| 325 |
-
st.markdown("Support: https://
|
|
|
|
| 15 |
streamlit_api_key = st.secrets["STREAMLIT_API_KEY"]
|
| 16 |
|
| 17 |
|
| 18 |
+
system_prompt = """<system_prompt> # Electrical Project Assistant
|
| 19 |
+
|
| 20 |
+
## Assistant
|
| 21 |
+
- Assistant is an Electrical Project Assistant dedicated to providing accurate and reliable information based on its knowledge base.
|
| 22 |
+
- Assistant is designed to aid the User in electrical engineering and design questions, focusing on construction codes in Texas, USA.
|
| 23 |
+
- Assistant has the persona of a wise, experienced electrical engineer, designer, and specification writer.
|
| 24 |
+
- Assistant answers queries about this project's Construction Documents Specifications
|
| 25 |
+
|
| 26 |
+
## Assistant's Task
|
| 27 |
+
- Assistant's primary task is to answer User's questions with clear and reliable responses.
|
| 28 |
+
- Assistant's responses are solely based on the information available in its knowledge base.
|
| 29 |
+
|
| 30 |
+
## Constraints
|
| 31 |
+
- Assistant never makes assumptions or guesses -- it always refers to its knowledge base.
|
| 32 |
+
- Assistant always provides a reference and link to the knowledge base source in its responses.
|
| 33 |
+
|
| 34 |
+
## Inability to Respond
|
| 35 |
+
- If a definitive answer is not available in the knowledge base, Assistant acknowledges its inability and informs the User it cannot provide a response.
|
| 36 |
+
|
| 37 |
+
## Writing Style
|
| 38 |
+
- Assistant communicates as a knowledgeable and experienced electrical engineer, familiar with the electrical construction codes in Texas, USA.
|
| 39 |
+
- Assistant's responses are factual, clear, and concise.
|
| 40 |
+
|
| 41 |
+
## Hot Keys
|
| 42 |
+
p = list the PDF source pages and their URLS for the previous chat response from Assistant. List the full exact URLS from the source data.
|
| 43 |
+
s = summarize the previous chat response from Assistant
|
| 44 |
+
r = generate a Request for Information (RFI) on the subject asking for clarification on the subject.
|
| 45 |
+
e = generate a draft email focusing directly on the subject or main question. Omit any initial greetings or pleasantries, such as 'I hope this message finds you well.'
|
| 46 |
+
t = show any data from the previous chat response in table format
|
| 47 |
+
|
| 48 |
+
## Response
|
| 49 |
+
- Assistant always answers questions with clear and reliable responses solely based on the information available in its knowledge base.
|
| 50 |
+
- Assistant always cites and links to the Source from its knowledge base in its responses.
|
| 51 |
+
- Assistant always reminds the User to check the original documents to ensure the accuracy of the information provided.
|
| 52 |
+
- Always Extract and list the source URLs from the provided data.
|
| 53 |
+
- Search for the exact phrase "Source: " followed by a URL.
|
| 54 |
+
- List each URL verbatim as it appears after "Source: ". Example: If the data contains "Source: https://www.bigstateelectric.com/ai/assistant/specs/utsa2/pages/UTSA_page_345.pdf", respond with "Source 1: https://www.bigstateelectric.com/ai/assistant/specs/utsa2/pages/UTSA_page_345.pdf" and so on. </system_prompt>"""
|
| 55 |
|
| 56 |
questions = [
|
| 57 |
+
"Identify and provide the standard color codes for electrical conductors as specified in the project documents, focusing on the section detailing wire identification for power circuits.",
|
| 58 |
+
"Summarize all annotations and list the PDF pages where they were made.",
|
| 59 |
+
"Create RFI on the subject. The RFI creator is 'Big State Electric'",
|
| 60 |
+
"System installer",
|
| 61 |
+
"Docking Station",
|
| 62 |
+
"Outdoor grounding requirements",
|
| 63 |
"List the PDF source pages and their URLS for the previous chat response from Assistant. List the full exact URLs from the source data.",
|
| 64 |
+
"Draft a formal business email using context provided in the chat. Omit any initial greetings or pleasantries. Use a colon after the \"Dear\" part.",
|
|
|
|
| 65 |
"""Write article about the subject in the following format:
|
| 66 |
<article_format> ## Engaging Article Title
|
| 67 |
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
about = """
|
| 90 |
+
- This app is designed to help you find information about the project's Construction Documents Specifications.
|
| 91 |
+
- Source document: https://www.bigstateelectric.com/ai/specs/uhs/source/uhs_palo_alto.pdf
|
| 92 |
- Enter your question in the chat box on the right.
|
| 93 |
+
- Hotkeys: e = Email draft. p = List ref URLs. s = summarize response. r = RFI creation. t = show previous data in table.
|
| 94 |
- Choose how many pages of "Results" you would like to get from the knowledge base and added to the AI prompt. Increase the number to extract more information from the knowledge base.
|
| 95 |
- After the first prompt, choose whether you want another knowledge base search for the next prompt using the button below.
|
| 96 |
- The PDF pages from the knowledge base are published online and citable. Each PDF page has a link at the bottom going directly the the PDF source page so it can be seen in context.
|
| 97 |
- This app works best on desktop browsers and is not yet optimized for mobile devices.
|
| 98 |
+
- BSE Chatbot version 0.1 (c) 2024
|
| 99 |
"""
|
| 100 |
|
| 101 |
def check_password():
|
|
|
|
| 115 |
|
| 116 |
# Show input for password.
|
| 117 |
st.text_input(
|
| 118 |
+
"Password for Assistant", type="password", on_change=password_entered, key="password"
|
| 119 |
)
|
| 120 |
if "password_correct" in st.session_state:
|
| 121 |
st.error("😕 Password incorrect")
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
st.set_page_config(
|
| 132 |
+
page_title="BSE Specification Assistant",
|
| 133 |
+
page_icon="favicon.ico",
|
| 134 |
layout="wide",
|
| 135 |
initial_sidebar_state="auto"
|
| 136 |
)
|
|
|
|
| 210 |
cleaned_text = text_without_tags.strip()
|
| 211 |
return cleaned_text
|
| 212 |
|
| 213 |
+
def truncate_prompt_last_tokens(prompt, max_tokens=4000):
|
| 214 |
encoding = tiktoken.get_encoding("cl100k_base")
|
| 215 |
encoded_prompt = encoding.encode(prompt)
|
| 216 |
|
|
|
|
| 231 |
chain = prompt | chat
|
| 232 |
try:
|
| 233 |
# Truncate the prompt to the last history and user query
|
| 234 |
+
truncated_prompt = truncate_prompt_last_tokens("\n".join([f"{role}: {msg}" for role, msg in st.session_state.messages]), max_tokens=4000)
|
| 235 |
|
| 236 |
for chunk in chain.stream({"text": truncated_prompt}):
|
| 237 |
content = chunk.content
|
|
|
|
| 245 |
except Exception as e:
|
| 246 |
# Handle the exception
|
| 247 |
error_message = f"An error occurred while generating the response: {str(e)}"
|
| 248 |
+
message = f"bse,anon,generate_response,{e}"
|
| 249 |
level = "ERROR"
|
| 250 |
log_to_firestore("docmind-421208", message, level)
|
| 251 |
yield error_message
|
|
|
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
+
st.title("BSE Specifications Assistant")
|
| 279 |
+
st.markdown('''Knowledge Base Source: **University Health Community Hospital and Associated Projects - Palo Alto** - MM #22029.002 - March 22, 2024''')
|
| 280 |
#display questions
|
| 281 |
|
| 282 |
# st.markdown("---\n## Chat:")
|
|
|
|
| 287 |
# st.switch_page("streamlit_app_fb.py")
|
| 288 |
# if st.button("Phrase Search"):
|
| 289 |
# st.switch_page("pages/search_database_streamlit.py")
|
| 290 |
+
st.write("Welcome to the BSE Specs Assistant")
|
| 291 |
with st.expander("About"):
|
| 292 |
st.markdown(about)
|
| 293 |
with st.expander("Example Prompts"):
|
|
|
|
| 313 |
human = "{text}"
|
| 314 |
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])
|
| 315 |
|
| 316 |
+
if user_prompt := st.chat_input("Prompt about these specifications"):
|
| 317 |
original_user_prompt = user_prompt
|
| 318 |
+
message = f"bse,anon,p,{user_prompt[:200]}"
|
| 319 |
level = "INFO"
|
| 320 |
log_to_firestore("docmind-421208", message, level)
|
| 321 |
if st.session_state['query_pinecone_toggle']:
|
|
|
|
| 328 |
with st.spinner("Generating response..."):
|
| 329 |
try:
|
| 330 |
response = st.write_stream(generate_response(user_prompt))
|
| 331 |
+
message = f"bse,anon,r,{response[:200]}"
|
| 332 |
# print(message)
|
| 333 |
level = "INFO"
|
| 334 |
log_to_firestore("docmind-421208", message, level)
|
|
|
|
| 337 |
except Exception as e:
|
| 338 |
error_message = f"An error occurred while generating the response: {str(e)}"
|
| 339 |
st.error(error_message)
|
| 340 |
+
message = f"bse,anon,show_response,{e}"
|
| 341 |
level = "ERROR"
|
| 342 |
log_to_firestore("docmind-421208", message, level)
|
| 343 |
response = ""
|
|
|
|
| 361 |
st.markdown("<span style='color: green;'>☑<sup><sub> Knowledge base will be queried for the next message</sub></sup></span>", unsafe_allow_html=True)
|
| 362 |
else:
|
| 363 |
st.markdown("<span style='color:#8B8000;'>☐<sup><sub> Knowledge base will NOT be queried for the next message</sub></sup></span>", unsafe_allow_html=True)
|
| 364 |
+
st.markdown("Support: Contact https://truevis.com")
|
favicon.ico
ADDED
|
|
property-icon.ico
DELETED
|
Binary file (256 kB)
|
|
|
utils/privacy_policy.txt
CHANGED
|
@@ -1,10 +1,7 @@
|
|
| 1 |
-
Our web application ("App") is designed to help users find information
|
| 2 |
-
|
| 3 |
Information We Collect
|
| 4 |
a. Personal Information: When you create an account, we collect your email address and password. We also collect any additional information you provide voluntarily, such as your name or company details.
|
| 5 |
b. Usage Data: We log user prompts and responses to improve our service and provide a better user experience. This data may include the content of your queries and the information provided by the App in response.
|
| 6 |
-
c. Payment Information: If you subscribe to our service via Stripe.com, your payment information, such as credit card details, will be processed by Stripe. We do not store or have access to your complete credit card information.
|
| 7 |
-
How We Use Your Information
|
| 8 |
a. To provide and improve our service: We use the collected information to operate, maintain, and enhance the App's functionality and performance.
|
| 9 |
b. To personalize your experience: We may use your information to customize the App's content and features based on your preferences and past usage.
|
| 10 |
c. To communicate with you: We may use your email address to send you updates, notifications, or promotional messages related to the App. If you wish to be removed from our email list, please notify us.
|
|
|
|
| 1 |
+
Our web application ("App") is designed to help users find information building specifications and standards. This Privacy Policy outlines how we collect, use, and protect the personal information of our users.
|
|
|
|
| 2 |
Information We Collect
|
| 3 |
a. Personal Information: When you create an account, we collect your email address and password. We also collect any additional information you provide voluntarily, such as your name or company details.
|
| 4 |
b. Usage Data: We log user prompts and responses to improve our service and provide a better user experience. This data may include the content of your queries and the information provided by the App in response.
|
|
|
|
|
|
|
| 5 |
a. To provide and improve our service: We use the collected information to operate, maintain, and enhance the App's functionality and performance.
|
| 6 |
b. To personalize your experience: We may use your information to customize the App's content and features based on your preferences and past usage.
|
| 7 |
c. To communicate with you: We may use your email address to send you updates, notifications, or promotional messages related to the App. If you wish to be removed from our email list, please notify us.
|