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()
# Add Unicode font support
pdf.add_font('DejaVu', '', 'DejaVuSans.ttf', uni=True)
pdf.set_font('DejaVu', '', 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""))
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
page.insert_text((20, 20), "Cutting-Edge ML Areas (1-6)\n\n" + "\n".join(outline_items[:6]),
fontsize=10)
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'Download {file_label aprovada}'
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") 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..."):
try:
pdf_file = create_pdf_with_library(pdf_library, ml_outline)
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"
)
base64_pdf = base64.b64encode(pdf_bytes).decode('utf-8')
pdf_display = f''
st.markdown(pdf_display, unsafe_allow_html=True)
except FileNotFoundError:
st.error("Please download the DejaVuSans.ttf font and place it in the working directory for FPDF Unicode support")
except Exception as e:
st.error(f"Error generating PDF: {str(e)}")
st.markdown("""
""", unsafe_allow_html=True)