diff --git a/src/BowongModalFunctions/router/google.py b/src/BowongModalFunctions/router/google.py index c801ba2..7699cb7 100644 --- a/src/BowongModalFunctions/router/google.py +++ b/src/BowongModalFunctions/router/google.py @@ -209,29 +209,29 @@ async def inference_gemini(data: GeminiRequest, headers: Annotated[BundleHeaders return ModalTaskResponse(success=True, taskId=fn_call.object_id) -# @router.post('/inference_gemini_first_only', summary="使用Gemini推理hls视频流指定时间段的打点情况-仅第一阶段") -# async def inference_gemini_first_only(data: GeminiRequestFirstOnly, -# headers: Annotated[BundleHeaders, Header()], ) -> ModalTaskResponse: -# google_api_key = headers.x_google_api_key or os.environ.get("GOOGLE_API_KEY") -# if not google_api_key: -# raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Missing Google API Key") -# fn = modal.Function.from_name(config.modal_app_name, "video_inference_first_only", -# environment_name=config.modal_environment) -# fn_call = fn.spawn(google_api_key, data.product_cover_grid_uri_list, data.product_list) -# return ModalTaskResponse(success=True, taskId=fn_call.object_id) -# -# -# @router.post('/inference_gemini_second_only', summary="使用Gemini推理hls视频流指定时间段的打点情况-仅第二阶段") -# async def inference_gemini_second_only(data: GeminiRequestSecondOnly, -# headers: Annotated[BundleHeaders, Header()], ) -> ModalTaskResponse: -# google_api_key = headers.x_google_api_key or os.environ.get("GOOGLE_API_KEY") -# if not google_api_key: -# raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Missing Google API Key") -# fn = modal.Function.from_name(config.modal_app_name, "video_inference_second_only", -# environment_name=config.modal_environment) -# fn_call = fn.spawn(data.media_hls_url, google_api_key, data.identified_product_list, data.start_time, -# data.end_time, data.scale, data.options, data.prompt_label, data.last_product_text) -# return ModalTaskResponse(success=True, taskId=fn_call.object_id) +@router.post('/inference_gemini_first_only', summary="使用Gemini推理hls视频流指定时间段的打点情况-仅第一阶段") +async def inference_gemini_first_only(data: GeminiRequestFirstOnly, + headers: Annotated[BundleHeaders, Header()], ) -> ModalTaskResponse: + google_api_key = headers.x_google_api_key or os.environ.get("GOOGLE_API_KEY") + if not google_api_key: + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Missing Google API Key") + fn = modal.Function.from_name(config.modal_app_name, "video_inference_first_only", + environment_name=config.modal_environment) + fn_call = fn.spawn(google_api_key, data.product_cover_grid_uri_list, data.product_list) + return ModalTaskResponse(success=True, taskId=fn_call.object_id) + + +@router.post('/inference_gemini_second_only', summary="使用Gemini推理hls视频流指定时间段的打点情况-仅第二阶段") +async def inference_gemini_second_only(data: GeminiRequestSecondOnly, + headers: Annotated[BundleHeaders, Header()], ) -> ModalTaskResponse: + google_api_key = headers.x_google_api_key or os.environ.get("GOOGLE_API_KEY") + if not google_api_key: + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Missing Google API Key") + fn = modal.Function.from_name(config.modal_app_name, "video_inference_second_only", + environment_name=config.modal_environment) + fn_call = fn.spawn(data.media_hls_url, google_api_key, data.identified_product_list, data.start_time, + data.end_time, data.scale, data.options, data.prompt_label, data.last_product_text) + return ModalTaskResponse(success=True, taskId=fn_call.object_id) @router.get("/inference_gemini/{task_id}", summary="查询Gemini推理hls视频流指定时间段的打点任务") diff --git a/src/cluster/video_apps/hls_slice_inference.py b/src/cluster/video_apps/hls_slice_inference.py index 972be2d..c296643 100644 --- a/src/cluster/video_apps/hls_slice_inference.py +++ b/src/cluster/video_apps/hls_slice_inference.py @@ -562,7 +562,7 @@ with (downloader_image.imports()): logger.info( f"🥳一阶段推理完成JSON \n{json.dumps(identified_product_list, indent=4, ensure_ascii=False)}") logger.success("🎉推理完成") - return identified_product_list + return identified_product_list, None @app.function(cpu=(0.5, 64), timeout=1800, @@ -640,7 +640,7 @@ with (downloader_image.imports()): f"🥳二阶段推理完成JSON \n{json.dumps(product_timeline_info, indent=4, ensure_ascii=False)}") logger.success("🎉推理完成") - return product_timeline_info + return product_timeline_info, None @app.function(cpu=(0.5, 64), timeout=1800,