Python | Machine Learning | Coding | R
66K subscribers
1.19K photos
80 videos
150 files
857 links
Help and ads: @hussein_sheikho

Discover powerful insights with Python, Machine Learning, Coding, and Rβ€”your essential toolkit for data-driven solutions, smart alg

List of our channels:
https://t.me/addlist/8_rRW2scgfRhOTc0

https://telega.io/?r=nikapsOH
Download Telegram
Python | Machine Learning | Coding | R
Photo
# πŸ“š Python Tutorial: Convert EPUB to PDF (Preserving Images)
#Python #EPUB #PDF #EbookConversion #Automation

This comprehensive guide will show you how to convert EPUB files (including those with images) to high-quality PDFs using Python.

---

## πŸ”Ή Required Tools & Libraries
We'll use these Python packages:
- ebooklib - For EPUB parsing
- pdfkit (wrapper for wkhtmltopdf) - For PDF generation
- Pillow - For image handling (optional)

pip install ebooklib pdfkit pillow


Also install system dependencies:
# On Ubuntu/Debian
sudo apt-get install wkhtmltopdf

# On MacOS
brew install wkhtmltopdf

# On Windows (download from wkhtmltopdf.org)


---

## πŸ”Ή Step 1: Extract EPUB Contents
First, we'll unpack the EPUB file to access its HTML and images.

from ebooklib import epub
from bs4 import BeautifulSoup
import os

def extract_epub(epub_path, output_dir):
book = epub.read_epub(epub_path)

# Create output directory
os.makedirs(output_dir, exist_ok=True)

# Extract all items (chapters, images, styles)
for item in book.get_items():
if item.get_type() == epub.ITEM_IMAGE:
# Save images
with open(os.path.join(output_dir, item.get_name()), 'wb') as f:
f.write(item.get_content())
elif item.get_type() == epub.ITEM_DOCUMENT:
# Save HTML chapters
with open(os.path.join(output_dir, item.get_name()), 'wb') as f:
f.write(item.get_content())

return [item.get_name() for item in book.get_items() if item.get_type() == epub.ITEM_DOCUMENT]


---

## πŸ”Ή Step 2: Convert HTML to PDF
Now we'll convert the extracted HTML files to PDF while preserving images.

import pdfkit
from PIL import Image # For image validation (optional)

def html_to_pdf(html_files, output_pdf, base_dir):
options = {
'encoding': "UTF-8",
'quiet': '',
'enable-local-file-access': '', # Critical for local images
'no-outline': None,
'margin-top': '15mm',
'margin-right': '15mm',
'margin-bottom': '15mm',
'margin-left': '15mm',
}

# Validate images (optional)
for html_file in html_files:
soup = BeautifulSoup(open(os.path.join(base_dir, html_file)), 'html.parser')
for img in soup.find_all('img'):
img_path = os.path.join(base_dir, img['src'])
try:
Image.open(img_path) # Validate image
except Exception as e:
print(f"Image error in {html_file}: {e}")
img.decompose() # Remove broken images

# Convert to PDF
pdfkit.from_file(
[os.path.join(base_dir, f) for f in html_files],
output_pdf,
options=options
)


---

## πŸ”Ή Step 3: Complete Conversion Function
Combine everything into a single workflow.

def epub_to_pdf(epub_path, output_pdf, temp_dir="temp_epub"):
try:
print(f"Converting {epub_path} to PDF...")

# Step 1: Extract EPUB
print("Extracting EPUB contents...")
html_files = extract_epub(epub_path, temp_dir)

# Step 2: Convert to PDF
print("Generating PDF...")
html_to_pdf(html_files, output_pdf, temp_dir)

print(f"Success! PDF saved to {output_pdf}")
return True

except Exception as e:
print(f"Conversion failed: {str(e)}")
return False
finally:
# Clean up temporary files
if os.path.exists(temp_dir):
import shutil
shutil.rmtree(temp_dir)


---

## πŸ”Ή Advanced Options
### 1. Custom Styling
Add CSS to improve PDF appearance:

def html_to_pdf(html_files, output_pdf, base_dir):
options = {
# ... previous options ...
'user-style-sheet': 'styles.css', # Custom CSS
}

# Create CSS file if needed
css = """
body { font-family: "Times New Roman", serif; font-size: 12pt; }
img { max-width: 100%; height: auto; }
"""
with open(os.path.join(base_dir, 'styles.css'), 'w') as f:
f.write(css)

pdfkit.from_file(/* ... */)
❀10πŸ”₯2πŸŽ‰1
πŸ“š JaidedAI/EasyOCR β€” an open-source Python library for Optical Character Recognition (OCR) that's easy to use and supports over 80 languages out of the box.

### πŸ” Key Features:

πŸ”Έ Extracts text from images and scanned documents β€” including handwritten notes and unusual fonts
πŸ”Έ Supports a wide range of languages like English, Russian, Chinese, Arabic, and more
πŸ”Έ Built on PyTorch β€” uses modern deep learning models (not the old-school Tesseract)
πŸ”Έ Simple to integrate into your Python projects

### βœ… Example Usage:

import easyocr

reader = easyocr.Reader(['en', 'ru']) # Choose supported languages
result = reader.readtext('image.png')


### πŸ“Œ Ideal For:

βœ… Text extraction from photos, scans, and documents
βœ… Embedding OCR capabilities in apps (e.g. automated data entry)

πŸ”— GitHub: https://github.com/JaidedAI/EasyOCR

πŸ‘‰ Follow us for more: @DataScienceN

#Python #OCR #MachineLearning #ComputerVision #EasyOCR
❀3πŸ‘Ž1πŸŽ‰1
This media is not supported in your browser
VIEW IN TELEGRAM
🧹 ObjectClear β€” an AI-powered tool for removing objects from images effortlessly.

βš™οΈ What It Can Do:

πŸ–ΌοΈ Upload any image
🎯 Select the object you want to remove
🌟 The model automatically erases the object and intelligently reconstructs the background

⚑️ Under the Hood:

β€” Uses Segment Anything (SAM) by Meta for object segmentation
β€” Leverages Inpaint-Anything for realistic background generation
β€” Works in your browser with an intuitive Gradio UI

βœ”οΈ Fully open-source and can be run locally.

πŸ“Ž GitHub: https://github.com/zjx0101/ObjectClear

#AI #ImageEditing #ComputerVision #Gradio #OpenSource #Python


βœ‰οΈ Our Telegram channels: https://t.me/addlist/0f6vfFbEMdAwODBk

πŸ“± Our WhatsApp channel: https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Please open Telegram to view this post
VIEW IN TELEGRAM
❀10
πŸš€ Comprehensive Tutorial: Build a Folder Monitoring & Intruder Detection System in Python

In this comprehensive, step-by-step tutorial, you will learn how to build a real-time folder monitoring and intruder detection system using Python.

πŸ” Your Goal:
Create a background program that:
- Monitors a specific folder on your computer.
- Instantly captures a photo using the webcam whenever someone opens that folder.
- Saves the photo with a timestamp in a secure folder.
- Runs automatically when Windows starts.
- Keeps running until you manually stop it (e.g., via Task Manager or a hotkey).

Read and get code: https://hackmd.io/@husseinsheikho/Build-a-Folder-Monitoring

#Python #Security #FolderMonitoring #IntruderDetection #OpenCV #FaceCapture #Automation #Windows #TaskScheduler #ComputerVision


βœ‰οΈ Our Telegram channels: https://t.me/addlist/0f6vfFbEMdAwODBk

πŸ“± Our WhatsApp channel: https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Please open Telegram to view this post
VIEW IN TELEGRAM
❀7πŸ”₯1πŸŽ‰1
πŸš€ Comprehensive Guide: How to Prepare for an Image Processing Job Interview – 500 Most Common Interview Questions

Let's start: https://hackmd.io/@husseinsheikho/IP

#ImageProcessing #ComputerVision #OpenCV #Python #InterviewPrep #DigitalImageProcessing #MachineLearning #AI #SignalProcessing #ComputerGraphics

βœ‰οΈ Our Telegram channels: https://t.me/addlist/0f6vfFbEMdAwODBk

πŸ“± Our WhatsApp channel: https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Please open Telegram to view this post
VIEW IN TELEGRAM
❀4πŸ‘Ž1πŸ”₯1
This media is not supported in your browser
VIEW IN TELEGRAM
πŸ₯‡ This repo is like gold for every data scientist!

βœ… Just open your browser; a ton of interactive exercises and real experiences await you. Any question about statistics, probability, Python, or machine learning, you'll get the answer right there! With code, charts, even animations. This way, you don't waste time, and what you learn really sticks in your mind!

⬅️ Data science statistics and probability topics
⬅️ Clustering
⬅️ Principal Component Analysis (PCA)
⬅️ Bagging and Boosting techniques
⬅️ Linear regression
⬅️ Neural networks and more...


β”Œ πŸ“‚ Int Data Science Python Dash
β””
🐱 GitHub-Repos

πŸ‘‰ @codeprogrammer

#Python #OpenCV #Automation #ML #AI #DEEPLEARNING #MACHINELEARNING #ComputerVision
Please open Telegram to view this post
VIEW IN TELEGRAM
❀9πŸ‘4πŸ’―1πŸ†1
python-docx: Create and Modify Word Documents #python

python-docx is a Python library for reading, creating, and updating Microsoft Word 2007+ (.docx) files.

Installation
pip install python-docx

Example
from docx import Document

document = Document()
document.add_paragraph("It was a dark and stormy night.")
<docx.text.paragraph.Paragraph object at 0x10f19e760>
document.save("dark-and-stormy.docx")

document = Document("dark-and-stormy.docx")
document.paragraphs[0].text
'It was a dark and stormy night.'

https://t.me/DataScienceN πŸš—
❀10πŸ”₯1
✨ Download a Free Python Cheat Sheet ✨

πŸ“– Download a free Python 3 cheat sheet PDF put together by the Real Python team.

🏷️ #Python
❀15πŸ’―2
πŸš€ 2025 FREE Study Recourses from SPOTO for y’all β€” Don’t Miss Out!
βœ… 100% Free Downloads
βœ… No signup / spam

πŸ“˜ #Python, Cybersecurity & Excel: https://bit.ly/4lYeVYp
πŸ“Š #Cloud Computing: https://bit.ly/45Rj1gm
☁️ #AI Kits: https://bit.ly/4m4bHTc
πŸ” #CCNA Courses: https://bit.ly/45TL7rm
🧠 Free Online Practice – Test Now: https://bit.ly/41Kurjr

September 8th to 21th, SPOTO launches the Lowest Price Ever on ALL products! πŸ”₯
Amazing Discounts for πŸ“Œ CCNA 200-301 πŸ“Œ CCNP 400-007 and more…
πŸ“² Contact admin to grab them: https://wa.link/uxde01
❀3
✨ Python Cheat Sheet ✨

πŸ“– Compact Python cheat sheet covering setup, syntax, data types, variables, strings, control flow, functions, classes, errors, and I/O.

🏷️ #Python
❀3
Media is too big
VIEW IN TELEGRAM
Released Real-Time Voice Cloning utility

Which clones speech and reproduces any phrases with your intonation in just a few seconds of recording.

It runs on #Python, generates speech in real time, and is completely local, no clouds or restrictions. 🫠

🌟 GitHub: https://github.com/CorentinJ/Real-Time-Voice-Cloning

πŸ‘‰  https://t.me/CodeProgrammer
Please open Telegram to view this post
VIEW IN TELEGRAM
❀5