import asyncio from celery_app import celery_app @celery_app.task def text_query_task(question: str): from endpoints.text import text_query # Import inside the function to avoid circular import loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) return loop.run_until_complete(text_query(question=question)) # ✅ Correct way to call async functions in Celery @celery_app.task def image_query_task(file_path: str, question: str): from endpoints.image import image_query # Import inside the function with open(file_path, "rb") as file: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) return loop.run_until_complete(image_query(file=file, question=question)) # ✅ Use event loop @celery_app.task def video_query_task(file_path: str, question: str): from endpoints.video import video_query # Import inside the function with open(file_path, "rb") as file: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) return loop.run_until_complete(video_query(file=file, question=question)) # ✅ Use event loop