# Streamlit UI st.title("πŸš€ Cutting-Edge ML Outline Generator") col1, col2 = st.columns(2) with col1: st.header("πŸ“ Markdown Outline") # Display the markdown content st.markdown(ml_markdown) # Create a download button for the markdown file st.download_button( label="Download Markdown", data=ml_markdown, file_name="ml_outline.md", mime="text/markdown" ) # Show the markdown source code in an expandable section with st.expander("View Markdown Source"): st.code(ml_markdown, language="markdown") with col2: st.header("πŸ“‘ PDF Preview & Demos") # Library Demos st.subheader("Library Demos") if st.button("Run PDF Library Demos"): with st.spinner("Running demos..."): # Create tabs for each demo demo_tabs = st.tabs(["PikePDF", "FPDF", "PyMuPDF", "Image Demo"]) with demo_tabs[0]: # pikepdf demo pike_pdf = demo_pikepdf() st.download_button("Download pikepdf Demo", pike_pdf, "pikepdf_demo.pdf") st.write("PikePDF demo created successfully!") st.info("This PDF contains the multilevel markdown outline in a two-column layout.") with demo_tabs[1]: # fpdf demo fpdf_pdf = demo_fpdf() st.download_button("Download fpdf Demo", fpdf_pdf, "fpdf_demo.pdf") st.write("FPDF demo created successfully!") st.info("This PDF contains the multilevel markdown outline in a two-column layout.") with demo_tabs[2]: # pymupdf demo pymupdf_pdf = demo_pymupdf() st.download_button("Download pymupdf Demo", pymupdf_pdf, "pymupdf_demo.pdf") st.write("PyMuPDF demo created successfully!") st.info("This PDF contains the multilevel markdown outline in a two-column layout.") with demo_tabs[3]: # Image demo img_data = demo_image_capture() st.image(img_data, caption="Demo Image (Camera simulation)") # Main PDF Generation st.subheader("Main Outline PDF") if st.button("Generate Main PDF"): with st.spinner("Generating PDF..."): try: pdf_bytes = create_main_pdf(ml_markdown) st.download_button( label="Download Main PDF", data=pdf_bytes, file_name="ml_outline.pdf", mime="application/pdf" ) # Display the PDF in the app base64_pdf = base64.b64encode(pdf_bytes).decode('utf-8') pdf_display = f''' ''' st.markdown(pdf_display, unsafe_allow_html=True) st.success("PDF generated successfully! The PDF displays the multilevel markdown outline in a two-column layout.") except Exception as e: st.error(f"Error generating PDF: {str(e)}") # Show the PDF rendering code in an expandable section with st.expander("View PDF Rendering Code"): st.code(""" # Process multilevel markdown for PDF output def markdown_to_pdf_content(markdown_text): # Convert markdown headers to styled text for PDF lines = markdown_text.strip().split('\\n') pdf_content = [] for line in lines: if line.startswith('# '): # Main header - will be handled separately pass elif line.startswith('## '): # Section header - add as a bold item section = line.replace('## ', '').strip() pdf_content.append(f"{section}") elif line.startswith('- '): # List item - add as a normal item item = line.replace('- ', '').strip() pdf_content.append(item) # Split the content for two columns mid_point = len(pdf_content) // 2 left_column = pdf_content[:mid_point] right_column = pdf_content[mid_point:] return left_column, right_column """, language="python") # Add custom CSS for better appearance st.markdown(""" """, unsafe_allow_html=True)