Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -162,6 +162,55 @@ def add_paper_buttons_and_links():
|
|
| 162 |
|
| 163 |
add_paper_buttons_and_links()
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
def generate_filename_old(prompt, file_type):
|
| 167 |
central = pytz.timezone('US/Central')
|
|
@@ -473,20 +522,6 @@ def get_chain(vectorstore):
|
|
| 473 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 474 |
return ConversationalRetrievalChain.from_llm(llm=llm, retriever=vectorstore.as_retriever(), memory=memory)
|
| 475 |
|
| 476 |
-
def process_user_input(user_question):
|
| 477 |
-
response = st.session_state.conversation({'question': user_question})
|
| 478 |
-
st.session_state.chat_history = response['chat_history']
|
| 479 |
-
for i, message in enumerate(st.session_state.chat_history):
|
| 480 |
-
template = user_template if i % 2 == 0 else bot_template
|
| 481 |
-
st.write(template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
|
| 482 |
-
# Save file output from PDF query results
|
| 483 |
-
filename = generate_filename(user_question, 'txt')
|
| 484 |
-
#create_file(filename, user_question, message.content)
|
| 485 |
-
response = message.content
|
| 486 |
-
user_prompt = user_question
|
| 487 |
-
create_file(filename, user_prompt, response, should_save)
|
| 488 |
-
#st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
| 489 |
-
|
| 490 |
def divide_prompt(prompt, max_length):
|
| 491 |
words = prompt.split()
|
| 492 |
chunks = []
|
|
|
|
| 162 |
|
| 163 |
add_paper_buttons_and_links()
|
| 164 |
|
| 165 |
+
def process_user_input(user_question):
|
| 166 |
+
response = st.session_state.conversation({'question': user_question})
|
| 167 |
+
st.session_state.chat_history = response['chat_history']
|
| 168 |
+
|
| 169 |
+
for i, message in enumerate(st.session_state.chat_history):
|
| 170 |
+
template = user_template if i % 2 == 0 else bot_template
|
| 171 |
+
st.write(template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
|
| 172 |
+
|
| 173 |
+
# Save file output from PDF query results
|
| 174 |
+
filename = generate_filename(user_question, 'txt')
|
| 175 |
+
create_file(filename, user_question, message.content, should_save)
|
| 176 |
+
|
| 177 |
+
# New functionality to create expanders and buttons
|
| 178 |
+
create_expanders_and_buttons(message.content)
|
| 179 |
+
|
| 180 |
+
def create_expanders_and_buttons(content):
|
| 181 |
+
# Split the content into sections based on headers
|
| 182 |
+
sections = content.split("\n\n")
|
| 183 |
+
for section in sections:
|
| 184 |
+
lines = section.split("\n")
|
| 185 |
+
if len(lines) > 1 and ":" in lines[0]: # Check for header and details
|
| 186 |
+
header = lines[0].replace(":", "").strip()
|
| 187 |
+
detail = " ".join(lines[1:]).strip()
|
| 188 |
+
|
| 189 |
+
with st.expander(header, expanded=False):
|
| 190 |
+
if st.button(f"Explore {header}"):
|
| 191 |
+
expanded_outline = "Expand on the feature: " + detail
|
| 192 |
+
chat_with_model(expanded_outline, header)
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def process_user_input_old(user_question):
|
| 197 |
+
response = st.session_state.conversation({'question': user_question})
|
| 198 |
+
st.session_state.chat_history = response['chat_history']
|
| 199 |
+
for i, message in enumerate(st.session_state.chat_history):
|
| 200 |
+
template = user_template if i % 2 == 0 else bot_template
|
| 201 |
+
st.write(template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
|
| 202 |
+
# Save file output from PDF query results
|
| 203 |
+
filename = generate_filename(user_question, 'txt')
|
| 204 |
+
#create_file(filename, user_question, message.content)
|
| 205 |
+
response = message.content
|
| 206 |
+
user_prompt = user_question
|
| 207 |
+
create_file(filename, user_prompt, response, should_save)
|
| 208 |
+
#st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
|
| 214 |
|
| 215 |
def generate_filename_old(prompt, file_type):
|
| 216 |
central = pytz.timezone('US/Central')
|
|
|
|
| 522 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 523 |
return ConversationalRetrievalChain.from_llm(llm=llm, retriever=vectorstore.as_retriever(), memory=memory)
|
| 524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
def divide_prompt(prompt, max_length):
|
| 526 |
words = prompt.split()
|
| 527 |
chunks = []
|