awacke1 commited on
Commit
d6b502d
·
verified ·
1 Parent(s): 7445db9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -9,6 +9,9 @@ import re
9
  import fitz # PyMuPDF
10
  from PIL import Image
11
 
 
 
 
12
  # Initial markdown content
13
  default_markdown = """# Cutting-Edge ML Outline
14
 
@@ -249,16 +252,12 @@ def create_main_pdf(markdown_text, base_font_size=10, auto_size=False):
249
  buffer.seek(0)
250
  return buffer.getvalue()
251
 
252
- # Function to convert PDF bytes to image using fitz (from backup.03302025-720pm.app.py)
253
  def pdf_to_image(pdf_bytes):
254
  try:
255
- # Open PDF from bytes
256
  doc = fitz.open(stream=pdf_bytes, filetype="pdf")
257
- # Get the first page
258
  page = doc[0]
259
- # Render page to pixmap with a zoom factor for clarity
260
  pix = page.get_pixmap(matrix=fitz.Matrix(2.0, 2.0)) # 2x zoom
261
- # Convert to PIL Image
262
  img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
263
  doc.close()
264
  return img
@@ -266,12 +265,8 @@ def pdf_to_image(pdf_bytes):
266
  st.error(f"Failed to render PDF preview: {e}")
267
  return None
268
 
269
- # Streamlit UI
270
- st.title("🚀 Cutting-Edge ML Outline Generator")
271
-
272
- # Sidebar for settings
273
  with st.sidebar:
274
- st.header("PDF Settings")
275
  auto_size = st.checkbox("Auto-size text", value=True)
276
  if not auto_size:
277
  base_font_size = st.slider("Base Font Size (points)", min_value=6, max_value=16, value=10, step=1)
@@ -287,13 +282,13 @@ if 'markdown_content' not in st.session_state:
287
  with st.spinner("Generating PDF..."):
288
  pdf_bytes = create_main_pdf(st.session_state.markdown_content, base_font_size, auto_size)
289
 
290
- # Display PDF preview using fitz
291
- st.subheader("PDF Preview")
292
- pdf_image = pdf_to_image(pdf_bytes)
293
- if pdf_image:
294
- st.image(pdf_image, caption="PDF Page 1", use_container_width=True)
295
- else:
296
- st.info("Download the PDF to view it locally.")
297
 
298
  # Download button
299
  st.download_button(
@@ -304,7 +299,6 @@ st.download_button(
304
  )
305
 
306
  # Markdown editor
307
- st.subheader("Edit Markdown Outline")
308
  edited_markdown = st.text_area(
309
  "Modify the markdown content below:",
310
  value=st.session_state.markdown_content,
 
9
  import fitz # PyMuPDF
10
  from PIL import Image
11
 
12
+ # Set page config for wide layout and collapsed sidebar
13
+ st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
14
+
15
  # Initial markdown content
16
  default_markdown = """# Cutting-Edge ML Outline
17
 
 
252
  buffer.seek(0)
253
  return buffer.getvalue()
254
 
255
+ # Function to convert PDF bytes to image using fitz
256
  def pdf_to_image(pdf_bytes):
257
  try:
 
258
  doc = fitz.open(stream=pdf_bytes, filetype="pdf")
 
259
  page = doc[0]
 
260
  pix = page.get_pixmap(matrix=fitz.Matrix(2.0, 2.0)) # 2x zoom
 
261
  img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
262
  doc.close()
263
  return img
 
265
  st.error(f"Failed to render PDF preview: {e}")
266
  return None
267
 
268
+ # Sidebar for settings (collapsed by default)
 
 
 
269
  with st.sidebar:
 
270
  auto_size = st.checkbox("Auto-size text", value=True)
271
  if not auto_size:
272
  base_font_size = st.slider("Base Font Size (points)", min_value=6, max_value=16, value=10, step=1)
 
282
  with st.spinner("Generating PDF..."):
283
  pdf_bytes = create_main_pdf(st.session_state.markdown_content, base_font_size, auto_size)
284
 
285
+ # Display PDF preview in a full-width container
286
+ with st.container():
287
+ pdf_image = pdf_to_image(pdf_bytes)
288
+ if pdf_image:
289
+ st.image(pdf_image, use_column_width=True)
290
+ else:
291
+ st.info("Download the PDF to view it locally.")
292
 
293
  # Download button
294
  st.download_button(
 
299
  )
300
 
301
  # Markdown editor
 
302
  edited_markdown = st.text_area(
303
  "Modify the markdown content below:",
304
  value=st.session_state.markdown_content,