File size: 4,301 Bytes
787b7f8
85a6b6e
 
787b7f8
 
 
85a6b6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787b7f8
85a6b6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787b7f8
85a6b6e
 
 
 
 
 
 
 
787b7f8
85a6b6e
 
 
 
 
 
 
 
 
 
 
 
787b7f8
85a6b6e
 
 
 
 
 
787b7f8
85a6b6e
 
787b7f8
85a6b6e
 
787b7f8
85a6b6e
 
 
 
 
 
 
 
 
 
787b7f8
85a6b6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787b7f8
85a6b6e
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import streamlit as st
import base64
from fpdf import FPDF
import pikepdf
import fitz  # pymupdf

# 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"
]

def create_pdf_with_library(library_name, outline_items):
    if library_name == "fpdf":
        pdf = FPDF(orientation='L', unit='mm', format='A4')
        pdf.add_page()
        pdf.set_font("Arial", size=10)
        
        # Left page (1-6)
        pdf.set_xy(10, 10)
        pdf.multi_cell(140, 5, "Cutting-Edge ML Areas (1-6)\n\n" + "\n".join(outline_items[:6]))
        
        # Right page (7-12)
        pdf.set_xy(150, 10)
        pdf.multi_cell(140, 5, "Cutting-Edge ML Areas (7-12)\n\n" + "\n".join(outline_items[6:]))
        
        filename = "ml_outline_fpdf.pdf"
        pdf.output(filename)
        return filename

    elif library_name == "pikepdf":
        pdf = pikepdf.Pdf.new()
        page = pikepdf.Page(pdf.make_stream(b""))
        # Simplified content for pikepdf
        pdf.pages.append(page)
        filename = "ml_outline_pikepdf.pdf"
        pdf.save(filename)
        return filename

    elif library_name == "pymupdf":
        doc = fitz.open()
        page = doc.new_page(width=842, height=595)  # A4 landscape
        # Left column
        page.insert_text((20, 20), "Cutting-Edge ML Areas (1-6)\n\n" + "\n".join(outline_items[:6]),
                        fontsize=10)
        # Right column
        page.insert_text((422, 20), "Cutting-Edge ML Areas (7-12)\n\n" + "\n".join(outline_items[6:]),
                        fontsize=10)
        filename = "ml_outline_pymupdf.pdf"
        doc.save(filename)
        return filename

def get_binary_file_downloader_html(bin_file, file_label='File'):
    with open(bin_file, 'rb') as f:
        data = f.read()
    bin_str = base64.b64encode(data).decode()
    href = f'<a href="data:application/octet-stream;base64,{bin_str}" download="{file_label}">Download {file_label}</a>'
    return href

# Streamlit UI
st.title("πŸš€ Cutting-Edge ML Outline Generator")

# Two-column layout
col1, col2 = st.columns(2)

with col1:
    st.header("πŸ“ Markdown Outline")
    outline_text = "\n".join(ml_outline)
    st.markdown(outline_text)
    
    # Download markdown file
    md_file = "ml_outline.md"
    with open(md_file, "w") as f:
        f.write(outline_text)
    st.markdown(get_binary_file_downloader_html(md_file, "ml_outline.md"), unsafe_allow_html=True)

with col2:
    st.header("πŸ“‘ PDF Preview")
    pdf_library = st.selectbox("Choose PDF Library", ["fpdf", "pikepdf", "pymupdf"])
    
    if st.button("Generate PDF"):
        with st.spinner("Generating PDF..."):
            pdf_file = create_pdf_with_library(pdf_library, ml_outline)
            
            # Auto-save and display PDF
            with open(pdf_file, "rb") as f:
                pdf_bytes = f.read()
            
            st.download_button(
                label="Download PDF",
                data=pdf_bytes,
                file_name=pdf_file,
                mime="application/pdf"
            )
            
            # Display PDF
            base64_pdf = base64.b64encode(pdf_bytes).decode('utf-8')
            pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="100%" height="400" type="application/pdf"></iframe>'
            st.markdown(pdf_display, unsafe_allow_html=True)

# Add some style
st.markdown("""
<style>
    .stButton>button {
        background-color: #4CAF50;
        color: white;
    }
    .stSelectbox {
        max-width: 300px;
    }
</style>
""", unsafe_allow_html=True)