Spaces:
Running
Running
adibak
commited on
Commit
·
257a4d5
1
Parent(s):
8880077
make upload zone around chat, and name+slider on sidebar
Browse files- app.py +72 -45
- strings.json +1 -1
app.py
CHANGED
@@ -144,7 +144,6 @@ CHAT_MESSAGES = 'chat_messages'
|
|
144 |
DOWNLOAD_FILE_KEY = 'download_file_name'
|
145 |
IS_IT_REFINEMENT = 'is_it_refinement'
|
146 |
ADDITIONAL_INFO = 'additional_info'
|
147 |
-
UPLOAD_CONTAINER_OPEN = 'upload_container_open'
|
148 |
|
149 |
logger = logging.getLogger(__name__)
|
150 |
|
@@ -252,6 +251,41 @@ def build_ui():
|
|
252 |
|
253 |
set_up_chat_ui()
|
254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
def set_up_chat_ui():
|
257 |
"""
|
@@ -276,6 +310,7 @@ def set_up_chat_ui():
|
|
276 |
for msg in history.messages:
|
277 |
st.chat_message(msg.type).code(msg.content, language='json')
|
278 |
|
|
|
279 |
prompt_container = st.container()
|
280 |
with prompt_container:
|
281 |
# Chat input below the uploader
|
@@ -283,56 +318,44 @@ def set_up_chat_ui():
|
|
283 |
placeholder=APP_TEXT['chat_placeholder'],
|
284 |
max_chars=GlobalConfig.LLM_MODEL_MAX_INPUT_LENGTH,
|
285 |
)
|
286 |
-
|
|
|
287 |
|
288 |
-
#
|
289 |
-
|
290 |
-
st.session_state[UPLOAD_CONTAINER_OPEN] = True
|
291 |
|
292 |
-
#
|
293 |
-
# This will create a container that acts as a sticky element
|
294 |
-
|
295 |
-
# Custom CSS
|
296 |
-
st.markdown(
|
297 |
-
'''
|
298 |
-
<style>
|
299 |
-
div[data-testid="stFileUploaderDropzoneInstructions"]{
|
300 |
-
height:30px;
|
301 |
-
}
|
302 |
-
</style>
|
303 |
-
''',
|
304 |
-
unsafe_allow_html=True
|
305 |
-
)
|
306 |
upload_container = st.container()
|
307 |
with upload_container:
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
)
|
316 |
|
317 |
-
|
318 |
-
|
319 |
-
reader = PdfReader(uploaded_pdf)
|
320 |
-
total_pages = len(reader.pages)
|
321 |
-
st.session_state["pdf_page_count"] = total_pages
|
322 |
-
|
323 |
-
# Slider for page range
|
324 |
-
max_slider = min(50, total_pages) # enforce 50 page limit
|
325 |
-
|
326 |
-
with st.sidebar:
|
327 |
-
st.slider(
|
328 |
-
label="5: Specify a page range to examine:",
|
329 |
-
min_value=1,
|
330 |
-
max_value=max_slider,
|
331 |
-
value=(1, max_slider),
|
332 |
-
key="page_range"
|
333 |
-
)
|
334 |
-
|
335 |
-
upload_container.float("bottom:70px;width:40%;font-size:10pt;right:7.5%;") # position above chat input
|
336 |
|
337 |
if prompt:
|
338 |
prompt_text = prompt
|
@@ -631,12 +654,16 @@ def _display_download_button(file_path: pathlib.Path):
|
|
631 |
:param file_path: The path of the .pptx file.
|
632 |
"""
|
633 |
with open(file_path, 'rb') as download_file:
|
|
|
|
|
634 |
st.download_button(
|
635 |
'Download PPTX file ⬇️',
|
636 |
data=download_file,
|
637 |
file_name='Presentation.pptx',
|
638 |
key=datetime.datetime.now()
|
639 |
)
|
|
|
|
|
640 |
|
641 |
|
642 |
def main():
|
|
|
144 |
DOWNLOAD_FILE_KEY = 'download_file_name'
|
145 |
IS_IT_REFINEMENT = 'is_it_refinement'
|
146 |
ADDITIONAL_INFO = 'additional_info'
|
|
|
147 |
|
148 |
logger = logging.getLogger(__name__)
|
149 |
|
|
|
251 |
|
252 |
set_up_chat_ui()
|
253 |
|
254 |
+
def apply_custom_css():
|
255 |
+
# Custom CSS so that the file upload area is kind of transparent, remains near the bottom but is
|
256 |
+
# a little enlarged for ease of use, and the extra things that are normally part of st.file_uploader,
|
257 |
+
# i.e. the "Drag and Drop File Here" label, the pdf's name and size label, upload icon, and browse files button,
|
258 |
+
# are hidden. What this CSS does is produce a simple 'zone' that the user can click or drop a file on.
|
259 |
+
st.markdown(
|
260 |
+
'''
|
261 |
+
<style>
|
262 |
+
|
263 |
+
div[data-testid="stFileUploader"]{
|
264 |
+
position:relative;
|
265 |
+
opacity:0.5;
|
266 |
+
width:200%;
|
267 |
+
height:100px;
|
268 |
+
left:-105%;
|
269 |
+
}
|
270 |
+
section[data-testid="stFileUploaderDropzone"]{
|
271 |
+
position:absolute;
|
272 |
+
width:100%;
|
273 |
+
height:100%;
|
274 |
+
top:0;
|
275 |
+
}
|
276 |
+
div[data-testid="stFileUploaderDropzoneInstructions"]{
|
277 |
+
display:none;
|
278 |
+
}
|
279 |
+
div[data-testid="stFileUploaderFile"]{
|
280 |
+
display:none;
|
281 |
+
}
|
282 |
+
div[data-testid="stFileUploaderFileName"]{
|
283 |
+
display:none;
|
284 |
+
}
|
285 |
+
</style>
|
286 |
+
''',
|
287 |
+
unsafe_allow_html=True
|
288 |
+
)
|
289 |
|
290 |
def set_up_chat_ui():
|
291 |
"""
|
|
|
310 |
for msg in history.messages:
|
311 |
st.chat_message(msg.type).code(msg.content, language='json')
|
312 |
|
313 |
+
# container to hold chat field
|
314 |
prompt_container = st.container()
|
315 |
with prompt_container:
|
316 |
# Chat input below the uploader
|
|
|
318 |
placeholder=APP_TEXT['chat_placeholder'],
|
319 |
max_chars=GlobalConfig.LLM_MODEL_MAX_INPUT_LENGTH,
|
320 |
)
|
321 |
+
# make it stick near bottom
|
322 |
+
prompt_container.float("bottom:40px;width:50%;z-index:999;font-size:10pt;")
|
323 |
|
324 |
+
# some CSS to simplify the look of the upload area
|
325 |
+
apply_custom_css()
|
|
|
326 |
|
327 |
+
# container to hold uploader
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
upload_container = st.container()
|
329 |
with upload_container:
|
330 |
+
uploaded_pdf = st.file_uploader(
|
331 |
+
"",
|
332 |
+
type=["pdf"],
|
333 |
+
label_visibility="visible",
|
334 |
+
)
|
335 |
+
|
336 |
+
# PDF Processing and Slider Logic
|
337 |
+
if uploaded_pdf:
|
338 |
+
reader = PdfReader(uploaded_pdf)
|
339 |
+
total_pages = len(reader.pages)
|
340 |
+
st.session_state["pdf_page_count"] = total_pages
|
341 |
+
|
342 |
+
# Slider for page range
|
343 |
+
max_slider = min(50, total_pages) # enforce 50 page limit
|
344 |
+
|
345 |
+
with st.sidebar:
|
346 |
+
# display the pdf's name
|
347 |
+
st.text(f"PDF Uploaded: {uploaded_pdf.name}")
|
348 |
+
|
349 |
+
st.slider(
|
350 |
+
label="4: Specify a page range to examine:",
|
351 |
+
min_value=1,
|
352 |
+
max_value=max_slider,
|
353 |
+
value=(1, max_slider),
|
354 |
+
key="page_range"
|
355 |
)
|
356 |
|
357 |
+
# make container stay near bottom too, but surround the chat and have dotted border for the visual cue
|
358 |
+
upload_container.float("border-style:dashed solid;bottom:10px;width:150%;height:100px;font-size:10pt;left:0;")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
359 |
|
360 |
if prompt:
|
361 |
prompt_text = prompt
|
|
|
654 |
:param file_path: The path of the .pptx file.
|
655 |
"""
|
656 |
with open(file_path, 'rb') as download_file:
|
657 |
+
print("entered")
|
658 |
+
print(f"filepath={file_path}")
|
659 |
st.download_button(
|
660 |
'Download PPTX file ⬇️',
|
661 |
data=download_file,
|
662 |
file_name='Presentation.pptx',
|
663 |
key=datetime.datetime.now()
|
664 |
)
|
665 |
+
|
666 |
+
print("download")
|
667 |
|
668 |
|
669 |
def main():
|
strings.json
CHANGED
@@ -35,6 +35,6 @@
|
|
35 |
"Did you know that SlideDeck AI supports eight LLMs that generate contents in different styles?",
|
36 |
"Did you know that SlideDeck AI can create a presentation based on any uploaded PDF file?"
|
37 |
],
|
38 |
-
"chat_placeholder": "Write the topic or instructions here. You can also upload a PDF
|
39 |
"like_feedback": "If you like SlideDeck AI, please consider leaving a heart ❤\uFE0F on the [Hugging Face Space](https://huggingface.co/spaces/barunsaha/slide-deck-ai/) or a star ⭐ on [GitHub](https://github.com/barun-saha/slide-deck-ai). Your [feedback](https://forms.gle/JECFBGhjvSj7moBx9) is appreciated."
|
40 |
}
|
|
|
35 |
"Did you know that SlideDeck AI supports eight LLMs that generate contents in different styles?",
|
36 |
"Did you know that SlideDeck AI can create a presentation based on any uploaded PDF file?"
|
37 |
],
|
38 |
+
"chat_placeholder": "Write the topic or instructions here. You can also click or drop to upload a PDF in this area.",
|
39 |
"like_feedback": "If you like SlideDeck AI, please consider leaving a heart ❤\uFE0F on the [Hugging Face Space](https://huggingface.co/spaces/barunsaha/slide-deck-ai/) or a star ⭐ on [GitHub](https://github.com/barun-saha/slide-deck-ai). Your [feedback](https://forms.gle/JECFBGhjvSj7moBx9) is appreciated."
|
40 |
}
|