Files
SaaS-PDF/backend/app/extensions.py
Your Name 6bb76e3f1b Add OCR, Background Removal, and PDF Editor features with tests
- Implemented OCR functionality using pytesseract for image and PDF text extraction.
- Added Background Removal service using rembg for image processing.
- Developed PDF Editor service for applying text annotations to PDF files.
- Created corresponding API routes for OCR, Background Removal, and PDF Editor.
- Added frontend components for OCR and Background Removal tools.
- Integrated feature flagging for new tools, ensuring they are disabled by default.
- Implemented comprehensive unit tests for OCR service, PDF editor, and background removal.
- Updated documentation to reflect new features and usage instructions.
- Added translations for new features in English, Arabic, and French.
2026-03-07 21:29:08 +02:00

58 lines
2.0 KiB
Python

"""Flask extensions initialization."""
from celery import Celery
from celery.schedules import crontab
from flask_cors import CORS
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from flask_talisman import Talisman
# Initialize extensions (will be bound to app in create_app)
cors = CORS()
limiter = Limiter(key_func=get_remote_address)
talisman = Talisman()
celery = Celery()
def init_celery(app):
"""Initialize Celery with Flask app context."""
celery.conf.broker_url = app.config["CELERY_BROKER_URL"]
celery.conf.result_backend = app.config["CELERY_RESULT_BACKEND"]
celery.conf.result_expires = app.config.get("FILE_EXPIRY_SECONDS", 1800)
celery.conf.task_serializer = "json"
celery.conf.result_serializer = "json"
celery.conf.accept_content = ["json"]
celery.conf.timezone = "UTC"
celery.conf.task_track_started = True
# Set task routes
celery.conf.task_routes = {
"app.tasks.convert_tasks.*": {"queue": "convert"},
"app.tasks.compress_tasks.*": {"queue": "compress"},
"app.tasks.image_tasks.*": {"queue": "image"},
"app.tasks.video_tasks.*": {"queue": "video"},
"app.tasks.pdf_tools_tasks.*": {"queue": "pdf_tools"},
"app.tasks.flowchart_tasks.*": {"queue": "flowchart"},
"app.tasks.ocr_tasks.*": {"queue": "image"},
"app.tasks.removebg_tasks.*": {"queue": "image"},
"app.tasks.pdf_editor_tasks.*": {"queue": "pdf_tools"},
}
# Celery Beat — periodic tasks
celery.conf.beat_schedule = {
"cleanup-expired-files": {
"task": "app.tasks.maintenance_tasks.cleanup_expired_files",
"schedule": crontab(minute="*/30"),
},
}
class ContextTask(celery.Task):
"""Make Celery tasks work with Flask app context."""
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return self.run(*args, **kwargs)
celery.Task = ContextTask
return celery