File size: 4,843 Bytes
787b7f8
85a6b6e
6d17d44
3edd9d1
6d17d44
787b7f8
85a6b6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787b7f8
6d17d44
3edd9d1
 
 
 
6d17d44
3edd9d1
 
 
6d17d44
3edd9d1
 
 
 
 
 
 
 
6d17d44
3edd9d1
 
 
6d17d44
3edd9d1
 
 
 
 
 
6d17d44
3edd9d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d17d44
 
 
 
 
 
 
 
 
 
3edd9d1
6d17d44
 
3edd9d1
787b7f8
6d17d44
 
3edd9d1
85a6b6e
787b7f8
85a6b6e
 
787b7f8
85a6b6e
787b7f8
85a6b6e
 
 
 
 
 
6d17d44
85a6b6e
6d17d44
787b7f8
85a6b6e
 
 
 
 
2a9458c
6d17d44
2a9458c
3edd9d1
 
 
2a9458c
6d17d44
2a9458c
 
 
3edd9d1
2a9458c
 
 
6d17d44
2a9458c
6d17d44
 
 
 
 
 
 
2a9458c
6d17d44
2a9458c
 
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import streamlit as st
import base64
import pdfkit
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"
]

def create_pdf_with_pdfkit(outline_items):
    # Create HTML content with two columns
    html_content = """
    <html>
    <head>
        <meta charset="UTF-8">
        <style>
            body {
                font-family: Arial, sans-serif;
                font-size: 12pt;
                margin: 20px;
            }
            .container {
                display: flex;
                width: 100%;
            }
            .column {
                width: 50%;
                padding: 20px;
            }
            h2 {
                color: #2c3e50;
                font-size: 16pt;
            }
            ul {
                list-style-type: none;
                padding-left: 0;
            }
            li {
                margin: 10px 0;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="column">
                <h2>Cutting-Edge ML Areas (1-6)</h2>
                <ul>
    """
    
    # Add items 1-6
    for item in outline_items[:6]:
        html_content += f"<li>{item}</li>"
    
    html_content += """
                </ul>
            </div>
            <div class="column">
                <h2>Cutting-Edge ML Areas (7-12)</h2>
                <ul>
    """
    
    # Add items 7-12
    for item in outline_items[6:]:
        html_content += f"<li>{item}</li>"
    
    html_content += """
                </ul>
            </div>
        </div>
    </body>
    </html>
    """
    
    # Convert HTML to PDF with pdfkit
    options = {
        'page-size': 'A4',
        'orientation': 'Landscape',
        'encoding': 'UTF-8',
        'margin-top': '0.5in',
        'margin-right': '0.5in',
        'margin-bottom': '0.5in',
        'margin-left': '0.5in',
    }
    
    # Create PDF in memory
    pdf_bytes = pdfkit.from_string(html_content, False, options=options)
    return pdf_bytes

def get_binary_file_downloader_html(bin_data, file_label='File'):
    bin_str = base64.b64encode(bin_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")

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")
    
    if st.button("Generate PDF"):
        with st.spinner("Generating PDF..."):
            try:
                pdf_bytes = create_pdf_with_pdfkit(ml_outline)
                
                # Save to file for download
                with open("ml_outline.pdf", "wb") as f:
                    f.write(pdf_bytes)
                
                # Download button
                st.download_button(
                    label="Download PDF",
                    data=pdf_bytes,
                    file_name="ml_outline.pdf",
                    mime="application/pdf"
                )
                
                # Fix PDF viewer
                base64_pdf = base64.b64encode(pdf_bytes).decode('utf-8')
                pdf_display = f'''
                    <embed 
                        src="data:application/pdf;base64,{base64_pdf}" 
                        width="100%" 
                        height="400px" 
                        type="application/pdf">
                '''
                st.markdown(pdf_display, unsafe_allow_html=True)
                
            except Exception as e:
                st.error(f"Error generating PDF: {str(e)}")

st.markdown("""
<style>
    .stButton>button {
        background-color: #4CAF50;
        color: white;
    }
</style>
""", unsafe_allow_html=True)