Spaces:
Running
Running
adibak
commited on
Commit
·
d1e63a2
1
Parent(s):
cb371b8
capitalize first letter in comments
Browse files
app.py
CHANGED
|
@@ -222,7 +222,7 @@ with st.sidebar:
|
|
| 222 |
value='2024-05-01-preview',
|
| 223 |
)
|
| 224 |
|
| 225 |
-
#
|
| 226 |
page_range_slider = st.slider('7: Specify a page range for the PDF file:',
|
| 227 |
1, GlobalConfig.MAX_ALLOWED_PAGES, [1, GlobalConfig.MAX_ALLOWED_PAGES])
|
| 228 |
st.session_state['page_range_slider'] = page_range_slider
|
|
@@ -260,7 +260,7 @@ def set_up_chat_ui():
|
|
| 260 |
"""
|
| 261 |
Prepare the chat interface and related functionality.
|
| 262 |
"""
|
| 263 |
-
#
|
| 264 |
st.session_state['start_page'] = st.session_state['page_range_slider'][0]
|
| 265 |
st.session_state['end_page'] = st.session_state['page_range_slider'][1]
|
| 266 |
|
|
@@ -290,14 +290,14 @@ def set_up_chat_ui():
|
|
| 290 |
):
|
| 291 |
prompt_text = prompt.text or ''
|
| 292 |
if prompt['files']:
|
| 293 |
-
#
|
| 294 |
uploaded_pdf = prompt['files'][0]
|
| 295 |
st.session_state['pdf_file'] = uploaded_pdf
|
| 296 |
# Apparently, Streamlit stores uploaded files in memory and clears on browser close
|
| 297 |
# https://docs.streamlit.io/knowledge-base/using-streamlit/where-file-uploader-store-when-deleted
|
| 298 |
|
| 299 |
-
#
|
| 300 |
-
#
|
| 301 |
if 'pdf_file' in st.session_state:
|
| 302 |
# get validated page range
|
| 303 |
st.session_state['start_page'], st.session_state['end_page'] = filem.validate_page_range(
|
|
@@ -305,11 +305,11 @@ def set_up_chat_ui():
|
|
| 305 |
st.session_state['start_page'],
|
| 306 |
st.session_state['end_page']
|
| 307 |
)
|
| 308 |
-
#
|
| 309 |
with st.sidebar:
|
| 310 |
st.text(f'Extracting pages {st.session_state["start_page"]} to {st.session_state["end_page"]} in {st.session_state["pdf_file"].name}')
|
| 311 |
|
| 312 |
-
#
|
| 313 |
st.session_state[ADDITIONAL_INFO] = filem.get_pdf_contents(
|
| 314 |
st.session_state['pdf_file'],
|
| 315 |
(st.session_state['start_page'],
|
|
|
|
| 222 |
value='2024-05-01-preview',
|
| 223 |
)
|
| 224 |
|
| 225 |
+
# Make slider with initial values
|
| 226 |
page_range_slider = st.slider('7: Specify a page range for the PDF file:',
|
| 227 |
1, GlobalConfig.MAX_ALLOWED_PAGES, [1, GlobalConfig.MAX_ALLOWED_PAGES])
|
| 228 |
st.session_state['page_range_slider'] = page_range_slider
|
|
|
|
| 260 |
"""
|
| 261 |
Prepare the chat interface and related functionality.
|
| 262 |
"""
|
| 263 |
+
# Set start and end page
|
| 264 |
st.session_state['start_page'] = st.session_state['page_range_slider'][0]
|
| 265 |
st.session_state['end_page'] = st.session_state['page_range_slider'][1]
|
| 266 |
|
|
|
|
| 290 |
):
|
| 291 |
prompt_text = prompt.text or ''
|
| 292 |
if prompt['files']:
|
| 293 |
+
# Store uploaded pdf in session state
|
| 294 |
uploaded_pdf = prompt['files'][0]
|
| 295 |
st.session_state['pdf_file'] = uploaded_pdf
|
| 296 |
# Apparently, Streamlit stores uploaded files in memory and clears on browser close
|
| 297 |
# https://docs.streamlit.io/knowledge-base/using-streamlit/where-file-uploader-store-when-deleted
|
| 298 |
|
| 299 |
+
# Check if pdf file is uploaded
|
| 300 |
+
# (we can use the same file if the user doesn't upload a new one)
|
| 301 |
if 'pdf_file' in st.session_state:
|
| 302 |
# get validated page range
|
| 303 |
st.session_state['start_page'], st.session_state['end_page'] = filem.validate_page_range(
|
|
|
|
| 305 |
st.session_state['start_page'],
|
| 306 |
st.session_state['end_page']
|
| 307 |
)
|
| 308 |
+
#Show sidebar text for page selection and file name
|
| 309 |
with st.sidebar:
|
| 310 |
st.text(f'Extracting pages {st.session_state["start_page"]} to {st.session_state["end_page"]} in {st.session_state["pdf_file"].name}')
|
| 311 |
|
| 312 |
+
# Get pdf contents
|
| 313 |
st.session_state[ADDITIONAL_INFO] = filem.get_pdf_contents(
|
| 314 |
st.session_state['pdf_file'],
|
| 315 |
(st.session_state['start_page'],
|