import streamlit as st import base64 from reportlab.lib.pagesizes import A4 from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer from reportlab.lib.styles import getSampleStyleSheet from reportlab.lib import colors import pikepdf import fpdf import fitz # pymupdf import cv2 from PIL import Image import imutils.video import io import os # Define the 12-point ML outline with emojis ml_outline = [ "🌟 1. Mixture of Experts (MoE)", "πŸ”₯ 2. Supervised Fine-Tuning (SFT) using PyTorch", "πŸ€– 3. Large Language Models (LLM) using Transformers", "πŸ“Š 4. Self-Rewarding Learning using NPS 0-10 and Verbatims", "πŸ‘ 5. Reinforcement Learning from Human Feedback (RLHF)", "πŸ”— 6. MergeKit: Merging Models to Same Embedding Space", "πŸ“ 7. DistillKit: Model Size Reduction with Spectrum Analysis", "🧠 8. Agentic RAG Agents using Document Inputs", "⏳ 9. Longitudinal Data Summarization from Multiple Docs", "πŸ“‘ 10. Knowledge Extraction using Markdown Knowledge Graphs", "πŸ—ΊοΈ 11. Knowledge Mapping with Mermaid Diagrams", "πŸ’» 12. ML Code Generation with Streamlit/Gradio/HTML5+JS" ] # Demo functions for PDF libraries def demo_pikepdf(): pdf = pikepdf.Pdf.new() pdf.pages.append(pikepdf.Page(pikepdf.Dictionary())) buffer = io.BytesIO() pdf.save(buffer) buffer.seek(0) return buffer.getvalue() def demo_fpdf(): pdf = fpdf.FPDF() pdf.add_page() pdf.set_font("Arial", size=12) pdf.cell(200, 10, txt="FPDF Demo", ln=True) buffer = io.BytesIO() pdf.output(buffer) buffer.seek(0) return buffer.getvalue() def demo_pymupdf(): doc = fitz.open() page = doc.new_page() page.insert_text((100, 100), "PyMuPDF Demo") buffer = io.BytesIO() doc.save(buffer) buffer.seek(0) return buffer.getvalue() # Demo function for image capture (using OpenCV as representative) def demo_image_capture(): try: cap = cv2.VideoCapture(0) ret, frame = cap.read() if ret: rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) img = Image.fromarray(rgb_frame) buffer = io.BytesIO() img.save(buffer, format="JPEG") buffer.seek(0) cap.release() return buffer.getvalue() cap.release() except: return None return None # Main PDF creation using ReportLab def create_main_pdf(outline_items): buffer = io.BytesIO() doc = SimpleDocTemplate(buffer, pagesize=(A4[1], A4[0])) # Landscape styles = getSampleStyleSheet() story = [] # Title style title_style = styles['Heading1'] title_style.textColor = colors.darkblue # Normal style normal_style = styles['Normal'] normal_style.fontSize = 10 normal_style.leading = 14 # Page 1: Items 1-6 story.append(Paragraph("Cutting-Edge ML Areas (1-6)", title_style)) story.append(Spacer(1, 12)) for item in outline_items[:6]: story.append(Paragraph(item, normal_style)) story.append(Spacer(1, 6)) # Page break story.append(Spacer(1, 500)) # Force new page # Page 2: Items 7-12 story.append(Paragraph("Cutting-Edge ML Areas (7-12)", title_style)) story.append(Spacer(1, 12)) for item in outline_items[6:]: story.append(Paragraph(item, normal_style)) story.append(Spacer(1, 6)) doc.build(story) buffer.seek(0) return buffer.getvalue() def get_binary_file_downloader_html(bin_data, file_label='File'): bin_str = base64.b64encode(bin_data).decode() href = f'Download {file_label}' return href # Streamlit UI st.title("πŸš€ Cutting-Edge ML Outline Generator") col1, col2 = st.columns(2) with col1: st.header("πŸ“ Markdown Outline") outline_text = "\n".join(ml_outline) st.markdown(outline_text) md_file = "ml_outline.md" with open(md_file, "w", encoding='utf-8') as f: f.write(outline_text) st.markdown(get_binary_file_downloader_html(outline_text.encode('utf-8'), "ml_outline.md"), unsafe_allow_html=True) with col2: st.header("πŸ“‘ PDF Preview & Demos") # Library Demos st.subheader("Library Demos") if st.button("Run PDF Demos"): with st.spinner("Running demos..."): # pikepdf demo pike_pdf = demo_pikepdf() st.download_button("Download pikepdf Demo", pike_pdf, "pikepdf_demo.pdf") # fpdf demo fpdf_pdf = demo_fpdf() st.download_button("Download fpdf Demo", fpdf_pdf, "fpdf_demo.pdf") # pymupdf demo pymupdf_pdf = demo_pymupdf() st.download_button("Download pymupdf Demo", pymupdf_pdf, "pymupdf_demo.pdf") # Image capture demo img_data = demo_image_capture() if img_data: st.image(img_data, caption="OpenCV Image Capture Demo") else: st.warning("Image capture demo failed - camera not detected") # Main PDF Generation if st.button("Generate Main PDF"): with st.spinner("Generating PDF..."): try: pdf_bytes = create_main_pdf(ml_outline) with open("ml_outline.pdf", "wb") as f: f.write(pdf_bytes) st.download_button( label="Download Main PDF", data=pdf_bytes, file_name="ml_outline.pdf", mime="application/pdf" ) base64_pdf = base64.b64encode(pdf_bytes).decode('utf-8') pdf_display = f''' ''' st.markdown(pdf_display, unsafe_allow_html=True) except Exception as e: st.error(f"Error generating PDF: {str(e)}") st.markdown(""" """, unsafe_allow_html=True)