Spaces:
Sleeping
Sleeping
Download backend/app/workers/remove_background.py from tech-ties/filezkit-backend: direct link, hf CLI and curl.
- Browser
- Download file 857 Bytes
-
https://huggingface.co/spaces/tech-ties/filezkit-backend/resolve/main/backend/app/workers/remove_background.py
- Command line
-
hf download hf://spaces/tech-ties/filezkit-backend/backend/app/workers/remove_background.py
-
curl -L -o remove_background.py https://huggingface.co/spaces/tech-ties/filezkit-backend/resolve/main/backend/app/workers/remove_background.py
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 | |
| 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() | |