From ee7ec172ea86dd860a5f3fa059b5e298230f0a4e Mon Sep 17 00:00:00 2001 From: Langevin Gael Date: Thu, 2 Jan 2025 14:41:53 +0100 Subject: [PATCH] avoid stop capture if isCapturing --- services/L_Llm.py | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/services/L_Llm.py b/services/L_Llm.py index 0fe964a6..9d8cb648 100644 --- a/services/L_Llm.py +++ b/services/L_Llm.py @@ -155,20 +155,36 @@ def onPredicate(predicateEvent): def describeImage(prompt): if runtime.isStarted('i01.llmImg'): llmImg = runtime.getService('i01.llmImg') - opencv = runtime.start('i01.opencv', 'OpenCV') - # make a subscription - i01_llmImg.subscribe('i01.opencv','publishImage') - #img = i01_llmImg.subscribe('i01.opencv','publishImage') - #response = llmImg.getImageResponse(img,prompt) - #llmImg.invoke("getResponse",["Always respond in french with a short description.", [img]]) - # capture and save an image - # the save image will be publishImage and be sent - # to the llmImg - opencv.capture() - opencv.saveImage() - sleep(0.1) - opencv.stopCapture() - + if runtime.isStarted('i01.opencv'): + opencv = runtime.getService('i01.opencv') + if opencv.isCapturing(): + # make a subscription + i01_llmImg.subscribe('i01.opencv','publishImage') + # capture and save an image + # the save image will be publishImage and be sent + # to the llmImg + opencv.saveImage() + else: + # make a subscription + i01_llmImg.subscribe('i01.opencv','publishImage') + # capture and save an image + # the save image will be publishImage and be sent + # to the llmImg + opencv.capture() + opencv.saveImage() + sleep(0.1) + opencv.stopCapture() + else: + opencv = runtime.start('i01.opencv', 'OpenCV') + # make a subscription + i01_llmImg.subscribe('i01.opencv','publishImage') + # capture and save an image + # the save image will be publishImage and be sent + # to the llmImg + opencv.capture() + opencv.saveImage() + sleep(0.1) + opencv.stopCapture() else: llmImg = runtime.start('i01.llmImg', 'LLM')