forge/backend/app/workers/tasks.py
DJP 7a804e896d Initial commit - FORGE AI unified platform
Features:
- Image generation (OpenAI, Gemini, Leonardo, Bria, Stability, Flux)
- Nano Banana iterative editing
- Video generation and upscaling
- Audio TTS, STT, sound effects (ElevenLabs)
- Text prompt studio and alt text
- User authentication with JWT/cookies
- Admin panel with voice management
- Job queue with Celery
- PostgreSQL + Redis backend
- Next.js 15 + FastAPI architecture

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-09 20:39:00 -05:00

116 lines
3.5 KiB
Python

"""Celery Tasks for background processing"""
import asyncio
from celery import shared_task
from app.workers.celery_app import celery_app
from app.services import (
image_generator,
image_upscaler,
background_remover,
video_generator,
video_upscaler,
subtitle_processor,
voice_to_text,
text_to_speech,
alt_text_generator
)
def run_async(coro):
"""Helper to run async functions in sync context"""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
return loop.run_until_complete(coro)
finally:
loop.close()
@celery_app.task(bind=True, name="process_image_generation")
def process_image_generation(self, job_id: str):
"""Process image generation job"""
try:
run_async(image_generator.generate(job_id))
except Exception as e:
self.retry(exc=e, countdown=60, max_retries=2)
@celery_app.task(bind=True, name="process_image_upscaling")
def process_image_upscaling(self, job_id: str):
"""Process image upscaling job"""
try:
run_async(image_upscaler.upscale(job_id))
except Exception as e:
self.retry(exc=e, countdown=60, max_retries=2)
@celery_app.task(bind=True, name="process_background_removal")
def process_background_removal(self, job_id: str):
"""Process background removal job"""
try:
run_async(background_remover.remove_background(job_id))
except Exception as e:
self.retry(exc=e, countdown=60, max_retries=2)
@celery_app.task(bind=True, name="process_video_generation")
def process_video_generation(self, job_id: str):
"""Process video generation job"""
try:
run_async(video_generator.generate(job_id))
except Exception as e:
self.retry(exc=e, countdown=120, max_retries=2)
@celery_app.task(bind=True, name="process_video_upscaling")
def process_video_upscaling(self, job_id: str):
"""Process video upscaling job"""
try:
run_async(video_upscaler.upscale(job_id))
except Exception as e:
self.retry(exc=e, countdown=120, max_retries=2)
@celery_app.task(bind=True, name="process_subtitles")
def process_subtitles(self, job_id: str):
"""Process subtitle generation job"""
try:
run_async(subtitle_processor.process(job_id))
except Exception as e:
self.retry(exc=e, countdown=60, max_retries=2)
@celery_app.task(bind=True, name="process_voice_to_text")
def process_voice_to_text(self, job_id: str):
"""Process voice to text transcription job"""
try:
run_async(voice_to_text.transcribe(job_id))
except Exception as e:
self.retry(exc=e, countdown=60, max_retries=2)
@celery_app.task(bind=True, name="process_text_to_speech")
def process_text_to_speech(self, job_id: str):
"""Process text to speech synthesis job"""
try:
run_async(text_to_speech.synthesize(job_id))
except Exception as e:
self.retry(exc=e, countdown=60, max_retries=2)
@celery_app.task(bind=True, name="process_speech_to_speech")
def process_speech_to_speech(self, job_id: str):
"""Process speech to speech conversion job"""
try:
run_async(text_to_speech.speech_to_speech(job_id))
except Exception as e:
self.retry(exc=e, countdown=60, max_retries=2)
@celery_app.task(bind=True, name="process_alt_text")
def process_alt_text(self, job_id: str):
"""Process alt text generation job"""
try:
run_async(alt_text_generator.generate(job_id))
except Exception as e:
self.retry(exc=e, countdown=60, max_retries=2)