Spaces:
Build error
Build error
Hkoradiya123
feat: Initialize frontend with Zustand for state management, Tailwind CSS for styling, and TypeScript for type safety
4854e2b Download backend/app/workers/tasks.py from jinksQspider/fmproService: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/spaces/jinksQspider/fmproService/resolve/main/backend/app/workers/tasks.py
- Command line
-
hf download hf://spaces/jinksQspider/fmproService/backend/app/workers/tasks.py
-
curl -L -o tasks.py https://huggingface.co/spaces/jinksQspider/fmproService/resolve/main/backend/app/workers/tasks.py
2.16 kB
| """Celery tasks for recognition and webhooks.""" | |
| import base64 | |
| from typing import Optional | |
| from uuid import UUID | |
| from app.core.database import SessionLocal | |
| from app.services.recognition_service import RecognitionService | |
| from app.workers.celery_app import celery_app | |
| def recognize_face_task( | |
| image_b64: str, | |
| tenant_id: str, | |
| user_id: str, | |
| threshold: float, | |
| return_bboxes: bool, | |
| ): | |
| image_bytes = base64.b64decode(image_b64) | |
| db = SessionLocal() | |
| try: | |
| return RecognitionService.recognize_from_bytes( | |
| db=db, | |
| image_bytes=image_bytes, | |
| tenant_id=UUID(tenant_id), | |
| user_id=UUID(user_id), | |
| threshold=threshold, | |
| return_bboxes=return_bboxes, | |
| source="async_queue", | |
| ) | |
| finally: | |
| db.close() | |
| def deliver_webhook_task(event_id: str): | |
| from app.services.webhook_service import WebhookService | |
| from app.models import WebhookEvent, WebhookEndpoint | |
| import httpx | |
| from app.core.config import settings | |
| db = SessionLocal() | |
| try: | |
| event = db.query(WebhookEvent).filter(WebhookEvent.id == UUID(event_id)).first() | |
| if not event: | |
| return | |
| endpoint = db.query(WebhookEndpoint).filter(WebhookEndpoint.id == event.endpoint_id).first() | |
| if not endpoint or not endpoint.is_active: | |
| return | |
| payload = event.payload | |
| headers = {"Content-Type": "application/json"} | |
| if endpoint.secret: | |
| headers["X-Webhook-Secret"] = endpoint.secret | |
| try: | |
| with httpx.Client(timeout=settings.WEBHOOK_TIMEOUT_SECONDS) as client: | |
| response = client.post(endpoint.url, content=payload, headers=headers) | |
| if 200 <= response.status_code < 300: | |
| WebhookService.mark_delivered(db, event, response.status_code) | |
| else: | |
| WebhookService.increment_attempt(db, event, response.status_code) | |
| except Exception: | |
| WebhookService.increment_attempt(db, event, None) | |
| finally: | |
| db.close() | |