import streamlit as st import fitz import base64 def display_scrollable_pages(): if st.session_state.get("uploaded_pdf_bytes") is not None: pdf_document = None try: pdf_document = fitz.open(stream=st.session_state.get("uploaded_pdf_bytes"), filetype="pdf") # CSS styles css = """ """ # Build HTML content html_content = css + '
' for page_num in range(1, st.session_state.get("chapters_starting_page")): page = pdf_document.load_page(page_num) pix = page.get_pixmap() img_bytes = pix.tobytes("png") base64_img = base64.b64encode(img_bytes).decode() html_content += f"""
Page {page_num + 1}
""" html_content += '
' # Render with st.html() st.html(html_content) except Exception as e: st.error(f"Failed to render PDF pages: {e}") finally: if pdf_document is not None: pdf_document.close() else: st.warning("No PDF file uploaded. Please upload a PDF file to generate questions from a chapter.") def select_chapter(): """ Displays a radio button selection for chapters extracted from the TOC. """ if st.session_state.get('chapters_dict') is not None: chapters = st.session_state['chapters_dict'] with st.container(): # Custom CSS for chapter selection st.html("""