awacke1 commited on
Commit
fba4d1f
Β·
verified Β·
1 Parent(s): 15f6774

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +146 -3
app.py CHANGED
@@ -1,4 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  def create_main_pdf(markdown_text):
 
2
  buffer = io.BytesIO()
3
  doc = SimpleDocTemplate(
4
  buffer,
@@ -25,7 +151,7 @@ def create_main_pdf(markdown_text):
25
  for col in (left_column, right_column):
26
  for item in col:
27
  if isinstance(item, list):
28
- main_item, sub_items = item # Unpack here
29
  total_items += 1 + len(sub_items)
30
  else:
31
  total_items += 1
@@ -39,7 +165,7 @@ def create_main_pdf(markdown_text):
39
  # Create custom styles
40
  title_style = styles['Heading1']
41
  title_style.textColor = colors.darkblue
42
- title_style.alignment = 1
43
  title_style.fontSize = min(16, base_font_size * 1.5)
44
 
45
  section_style = ParagraphStyle(
@@ -128,4 +254,21 @@ def create_main_pdf(markdown_text):
128
  story.append(table)
129
  doc.build(story)
130
  buffer.seek(0)
131
- return buffer.getvalue()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import base64
3
+ from reportlab.lib.pagesizes import A4
4
+ from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
5
+ from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
6
+ from reportlab.lib import colors
7
+ import io
8
+ import re
9
+
10
+ # Define the ML outline as a markdown string
11
+ ml_markdown = """# Cutting-Edge ML Outline
12
+
13
+ ## Core ML Techniques
14
+ 1. 🌟 **Mixture of Experts (MoE)**
15
+ - Conditional computation techniques
16
+ - Sparse gating mechanisms
17
+ - Training specialized sub-models
18
+
19
+ 2. πŸ”₯ **Supervised Fine-Tuning (SFT) using PyTorch**
20
+ - Loss function customization
21
+ - Gradient accumulation strategies
22
+ - Learning rate schedulers
23
+
24
+ 3. πŸ€– **Large Language Models (LLM) using Transformers**
25
+ - Attention mechanisms
26
+ - Tokenization strategies
27
+ - Position encodings
28
+
29
+ ## Training Methods
30
+ 4. πŸ“Š **Self-Rewarding Learning using NPS 0-10 and Verbatims**
31
+ - Custom reward functions
32
+ - Feedback categorization
33
+ - Signal extraction from text
34
+
35
+ 5. πŸ‘ **Reinforcement Learning from Human Feedback (RLHF)**
36
+ - Preference datasets
37
+ - PPO implementation
38
+ - KL divergence constraints
39
+
40
+ 6. πŸ”— **MergeKit: Merging Models to Same Embedding Space**
41
+ - TIES merging
42
+ - Task arithmetic
43
+ - SLERP interpolation
44
+
45
+ ## Optimization & Deployment
46
+ 7. πŸ“ **DistillKit: Model Size Reduction with Spectrum Analysis**
47
+ - Knowledge distillation
48
+ - Quantization techniques
49
+ - Model pruning strategies
50
+
51
+ 8. 🧠 **Agentic RAG Agents using Document Inputs**
52
+ - Vector database integration
53
+ - Query planning
54
+ - Self-reflection mechanisms
55
+
56
+ 9. ⏳ **Longitudinal Data Summarization from Multiple Docs**
57
+ - Multi-document compression
58
+ - Timeline extraction
59
+ - Entity tracking
60
+
61
+ ## Knowledge Representation
62
+ 10. πŸ“‘ **Knowledge Extraction using Markdown Knowledge Graphs**
63
+ - Entity recognition
64
+ - Relationship mapping
65
+ - Hierarchical structuring
66
+
67
+ 11. πŸ—ΊοΈ **Knowledge Mapping with Mermaid Diagrams**
68
+ - Flowchart generation
69
+ - Sequence diagram creation
70
+ - State diagrams
71
+
72
+ 12. πŸ’» **ML Code Generation with Streamlit/Gradio/HTML5+JS**
73
+ - Code completion
74
+ - Unit test generation
75
+ - Documentation synthesis
76
+ """
77
+
78
+ # Process multilevel markdown for PDF output
79
+ def markdown_to_pdf_content(markdown_text):
80
+ """Convert markdown text to a format suitable for PDF generation"""
81
+ lines = markdown_text.strip().split('\n')
82
+ pdf_content = []
83
+ in_list_item = False
84
+ current_item = None
85
+ sub_items = []
86
+
87
+ for line in lines:
88
+ line = line.strip()
89
+ if not line:
90
+ continue
91
+
92
+ if line.startswith('# '):
93
+ pass
94
+ elif line.startswith('## '):
95
+ if current_item and sub_items:
96
+ pdf_content.append([current_item, sub_items])
97
+ sub_items = []
98
+ current_item = None
99
+
100
+ section = line.replace('## ', '').strip()
101
+ pdf_content.append(f"<b>{section}</b>")
102
+ in_list_item = False
103
+ elif re.match(r'^\d+\.', line):
104
+ if current_item and sub_items:
105
+ pdf_content.append([current_item, sub_items])
106
+ sub_items = []
107
+
108
+ current_item = line.strip()
109
+ in_list_item = True
110
+ elif line.startswith('- ') and in_list_item:
111
+ sub_items.append(line.strip())
112
+ else:
113
+ if not in_list_item:
114
+ pdf_content.append(line.strip())
115
+
116
+ if current_item and sub_items:
117
+ pdf_content.append([current_item, sub_items])
118
+
119
+ mid_point = len(pdf_content) // 2
120
+ left_column = pdf_content[:mid_point]
121
+ right_column = pdf_content[mid_point:]
122
+
123
+ return left_column, right_column
124
+
125
+ # Main PDF creation using ReportLab
126
  def create_main_pdf(markdown_text):
127
+ """Create a single-page landscape PDF with the outline in two columns"""
128
  buffer = io.BytesIO()
129
  doc = SimpleDocTemplate(
130
  buffer,
 
151
  for col in (left_column, right_column):
152
  for item in col:
153
  if isinstance(item, list):
154
+ main_item, sub_items = item
155
  total_items += 1 + len(sub_items)
156
  else:
157
  total_items += 1
 
165
  # Create custom styles
166
  title_style = styles['Heading1']
167
  title_style.textColor = colors.darkblue
168
+ title_style.alignment = 1
169
  title_style.fontSize = min(16, base_font_size * 1.5)
170
 
171
  section_style = ParagraphStyle(
 
254
  story.append(table)
255
  doc.build(story)
256
  buffer.seek(0)
257
+ return buffer.getvalue()
258
+
259
+ # Streamlit UI
260
+ st.title("πŸš€ Cutting-Edge ML Outline Generator")
261
+
262
+ if st.button("Generate Main PDF"):
263
+ with st.spinner("Generating PDF..."):
264
+ pdf_bytes = create_main_pdf(ml_markdown)
265
+ st.download_button(
266
+ label="Download Main PDF",
267
+ data=pdf_bytes,
268
+ file_name="ml_outline.pdf",
269
+ mime="application/pdf"
270
+ )
271
+ base64_pdf = base64.b64encode(pdf_bytes).decode('utf-8')
272
+ pdf_display = f'<embed src="data:application/pdf;base64,{base64_pdf}" width="100%" height="400px" type="application/pdf">'
273
+ st.markdown(pdf_display, unsafe_allow_html=True)
274
+ st.success("PDF generated successfully!")