filezkit-backend / backend /app /workers /remove_background.py
tech-ties's picture
Claude Opus 4.8 (1M context)
Use lightweight cached u2netp rembg session for background-removal tools
c263a50
Raw History Blame Contribute Delete
857 Bytes
from app.core.celery_app import celery_app
from app.db.session import SessionLocal
from app.workers.conversion_helpers import complete_job, fail_job, outputs_dir, start_file_job
@celery_app.task
def remove_background_task(job_id: int):
db = SessionLocal()
job = None
try:
from app.workers.rembg_helpers import remove_background
job, input_path = start_file_job(db, job_id)
if not job:
return
with open(input_path, "rb") as f:
output_bytes = remove_background(f.read())
output_path = outputs_dir() / f"remove_background_{job_id}.png"
with open(output_path, "wb") as f:
f.write(output_bytes)
complete_job(db, job, output_path)
except Exception as e:
fail_job(db, job, "Remove Background", job_id, e)
finally:
db.close()