awacke1 commited on
Commit
9f3cf94
·
verified ·
1 Parent(s): 173ec9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -13
app.py CHANGED
@@ -2,8 +2,11 @@ import os
2
  import urllib.request
3
  import io
4
  import re
5
-
6
  import streamlit as st
 
 
 
 
7
  from PIL import Image
8
  import fitz # PyMuPDF
9
 
@@ -15,7 +18,6 @@ from reportlab.pdfbase import pdfmetrics
15
  from reportlab.pdfbase.ttfonts import TTFont
16
 
17
  # --- Step 1: Define and Download Available Emoji Fonts ---
18
- # List of available TTF filenames from the repository.
19
  font_files = [
20
  "Noto-COLRv1-emojicompat.ttf",
21
  "Noto-COLRv1-noflags.ttf",
@@ -27,10 +29,8 @@ font_files = [
27
  "NotoColorEmoji_WindowsCompatible.ttf"
28
  ]
29
 
30
- # Base URL to download the fonts from GitHub
31
  base_font_url = "https://github.com/googlefonts/noto-emoji/raw/main/fonts/"
32
 
33
- # Download each font if not already present.
34
  for font_file in font_files:
35
  if not os.path.exists(font_file):
36
  st.info(f"Downloading {font_file}...")
@@ -41,7 +41,6 @@ for font_file in font_files:
41
  st.error(f"Failed to download {font_file}: {e}")
42
 
43
  # --- Step 2: Allow User to Select the Emoji Font ---
44
- # Create a mapping for display (remove the .ttf extension for clarity)
45
  font_display_names = {f: f.replace(".ttf", "") for f in font_files}
46
  selected_font_file = st.sidebar.selectbox(
47
  "Select Emoji Font",
@@ -49,15 +48,10 @@ selected_font_file = st.sidebar.selectbox(
49
  format_func=lambda f: font_display_names[f]
50
  )
51
 
52
- # Register the selected font with ReportLab.
53
- # We use the display name (without .ttf) as the registered font name.
54
  registered_font_name = font_display_names[selected_font_file]
55
  pdfmetrics.registerFont(TTFont(registered_font_name, selected_font_file))
56
 
57
- # --- Streamlit App Setup ---
58
- st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
59
-
60
- # Default markdown content with emojis
61
  default_markdown = """# Cutting-Edge ML Outline
62
 
63
  ## Core ML Techniques
@@ -139,7 +133,7 @@ def markdown_to_pdf_content(markdown_text):
139
  continue
140
 
141
  if line.startswith('# '):
142
- # Optionally, skip main title
143
  pass
144
  elif line.startswith('## '):
145
  if current_item and sub_items:
@@ -205,7 +199,6 @@ def create_main_pdf(markdown_text, base_font_size=10, auto_size=False):
205
  section_font_size = base_font_size * 1.2
206
  title_font_size = min(16, base_font_size * 1.5)
207
 
208
- # Define styles using the selected emoji-supporting font.
209
  title_style = ParagraphStyle(
210
  'Heading1',
211
  parent=styles['Heading1'],
 
2
  import urllib.request
3
  import io
4
  import re
 
5
  import streamlit as st
6
+
7
+ # Set the page configuration as the very first Streamlit command.
8
+ st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
9
+
10
  from PIL import Image
11
  import fitz # PyMuPDF
12
 
 
18
  from reportlab.pdfbase.ttfonts import TTFont
19
 
20
  # --- Step 1: Define and Download Available Emoji Fonts ---
 
21
  font_files = [
22
  "Noto-COLRv1-emojicompat.ttf",
23
  "Noto-COLRv1-noflags.ttf",
 
29
  "NotoColorEmoji_WindowsCompatible.ttf"
30
  ]
31
 
 
32
  base_font_url = "https://github.com/googlefonts/noto-emoji/raw/main/fonts/"
33
 
 
34
  for font_file in font_files:
35
  if not os.path.exists(font_file):
36
  st.info(f"Downloading {font_file}...")
 
41
  st.error(f"Failed to download {font_file}: {e}")
42
 
43
  # --- Step 2: Allow User to Select the Emoji Font ---
 
44
  font_display_names = {f: f.replace(".ttf", "") for f in font_files}
45
  selected_font_file = st.sidebar.selectbox(
46
  "Select Emoji Font",
 
48
  format_func=lambda f: font_display_names[f]
49
  )
50
 
 
 
51
  registered_font_name = font_display_names[selected_font_file]
52
  pdfmetrics.registerFont(TTFont(registered_font_name, selected_font_file))
53
 
54
+ # --- Default Markdown Content with Emojis ---
 
 
 
55
  default_markdown = """# Cutting-Edge ML Outline
56
 
57
  ## Core ML Techniques
 
133
  continue
134
 
135
  if line.startswith('# '):
136
+ # Optionally skip main title
137
  pass
138
  elif line.startswith('## '):
139
  if current_item and sub_items:
 
199
  section_font_size = base_font_size * 1.2
200
  title_font_size = min(16, base_font_size * 1.5)
201
 
 
202
  title_style = ParagraphStyle(
203
  'Heading1',
204
  parent=styles['Heading1'],