Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,13 +11,13 @@ from PIL import Image
|
|
| 11 |
from reportlab.pdfgen import canvas
|
| 12 |
from reportlab.lib.pagesizes import letter, A4
|
| 13 |
from reportlab.lib.utils import ImageReader
|
| 14 |
-
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
|
| 15 |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
| 16 |
from reportlab.lib import colors
|
| 17 |
from reportlab.pdfbase import pdfmetrics
|
| 18 |
from reportlab.pdfbase.ttfonts import TTFont
|
| 19 |
import mistune
|
| 20 |
-
from
|
| 21 |
import fitz
|
| 22 |
import edge_tts
|
| 23 |
import asyncio
|
|
@@ -260,16 +260,8 @@ def create_pdf(markdown_texts, image_files, base_font_size=14, num_columns=2, ad
|
|
| 260 |
scale = min((page_width - 40) / img_width, (page_height - 40) / img_height)
|
| 261 |
new_width = img_width * scale
|
| 262 |
new_height = img_height * scale
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
buffer_img = io.BytesIO()
|
| 266 |
-
c = canvas.Canvas(buffer_img, pagesize=A4)
|
| 267 |
-
c.drawImage(img_path, x, y, new_width, new_height)
|
| 268 |
-
c.showPage()
|
| 269 |
-
c.save()
|
| 270 |
-
buffer_img.seek(0)
|
| 271 |
-
img_pdf = fitz.open(stream=buffer_img, filetype="pdf")
|
| 272 |
-
story.append(fitz.open(stream=buffer_img, filetype="pdf").load_page(0))
|
| 273 |
except Exception as e:
|
| 274 |
st.warning(f"Could not process image {img_path}: {e}")
|
| 275 |
continue
|
|
@@ -284,7 +276,7 @@ def pdf_to_image(pdf_bytes):
|
|
| 284 |
doc = fitz.open(stream=pdf_bytes, filetype="pdf")
|
| 285 |
images = []
|
| 286 |
for page in doc:
|
| 287 |
-
pix = page.
|
| 288 |
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
| 289 |
images.append(img)
|
| 290 |
doc.close()
|
|
@@ -501,7 +493,7 @@ with tab1:
|
|
| 501 |
st.markdown("---")
|
| 502 |
st.subheader("๐ผ Image Gallery")
|
| 503 |
image_files = glob.glob("*.png") + glob.glob("*.jpg") + glob.glob("*.jpeg")
|
| 504 |
-
image_cols = st.slider("Gallery Columns ๐ผ", min_value=1, max_value=15, value=
|
| 505 |
if image_files:
|
| 506 |
cols = st.columns(image_cols)
|
| 507 |
for idx, image_file in enumerate(image_files):
|
|
@@ -517,7 +509,7 @@ with tab1:
|
|
| 517 |
st.markdown("---")
|
| 518 |
st.subheader("๐ฅ Video Gallery")
|
| 519 |
video_files = glob.glob("*.mp4")
|
| 520 |
-
video_cols = st.slider("Gallery Columns ๐ฌ", min_value=1, max_value=5, value=
|
| 521 |
if video_files:
|
| 522 |
cols = st.columns(video_cols)
|
| 523 |
for idx, video_file in enumerate(video_files):
|
|
|
|
| 11 |
from reportlab.pdfgen import canvas
|
| 12 |
from reportlab.lib.pagesizes import letter, A4
|
| 13 |
from reportlab.lib.utils import ImageReader
|
| 14 |
+
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, Image as ReportLabImage
|
| 15 |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
| 16 |
from reportlab.lib import colors
|
| 17 |
from reportlab.pdfbase import pdfmetrics
|
| 18 |
from reportlab.pdfbase.ttfonts import TTFont
|
| 19 |
import mistune
|
| 20 |
+
from gTTS import gTTS
|
| 21 |
import fitz
|
| 22 |
import edge_tts
|
| 23 |
import asyncio
|
|
|
|
| 260 |
scale = min((page_width - 40) / img_width, (page_height - 40) / img_height)
|
| 261 |
new_width = img_width * scale
|
| 262 |
new_height = img_height * scale
|
| 263 |
+
story.append(ReportLabImage(img_path, width=new_width, height=new_height))
|
| 264 |
+
story.append(Spacer(1, spacer_height))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
except Exception as e:
|
| 266 |
st.warning(f"Could not process image {img_path}: {e}")
|
| 267 |
continue
|
|
|
|
| 276 |
doc = fitz.open(stream=pdf_bytes, filetype="pdf")
|
| 277 |
images = []
|
| 278 |
for page in doc:
|
| 279 |
+
pix = page.get pixmap(matrix=fitz.Matrix(2.0, 2.0))
|
| 280 |
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
| 281 |
images.append(img)
|
| 282 |
doc.close()
|
|
|
|
| 493 |
st.markdown("---")
|
| 494 |
st.subheader("๐ผ Image Gallery")
|
| 495 |
image_files = glob.glob("*.png") + glob.glob("*.jpg") + glob.glob("*.jpeg")
|
| 496 |
+
image_cols = st.slider("Gallery Columns ๐ผ", min_value=1, max_value=15, value=2, key="image_cols")
|
| 497 |
if image_files:
|
| 498 |
cols = st.columns(image_cols)
|
| 499 |
for idx, image_file in enumerate(image_files):
|
|
|
|
| 509 |
st.markdown("---")
|
| 510 |
st.subheader("๐ฅ Video Gallery")
|
| 511 |
video_files = glob.glob("*.mp4")
|
| 512 |
+
video_cols = st.slider("Gallery Columns ๐ฌ", min_value=1, max_value=5, value=1, key="video_cols")
|
| 513 |
if video_files:
|
| 514 |
cols = st.columns(video_cols)
|
| 515 |
for idx, video_file in enumerate(video_files):
|