-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (56 loc) · 2.72 KB
/
main.py
File metadata and controls
66 lines (56 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import logging
from src.utils import logger_config
from src.llm_services.OAI_text_to_speech import text_to_speech
from src.llm_services.OAI_text_to_text import text_to_text
from src.utils.audio import play_audio_with_pygame
from src.utils.camera import capture_image_from_ip_camera
from src.llm_services.OAI_image_to_text import image_to_text
from src.prompts.prompt_car_llm import prompt_user, prompt_system
from src.agents.goal import goal_agent,move_and_pic
from src.utils.robot_context import RobotContext
from config.config import SPEECH_ENABLED,CAPTURE_INTERVAL_SECONDS,LOG_LEVEL
import time
import warnings
import uuid
numeric_level = getattr(logging, LOG_LEVEL.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError(f'Invalid log level: {LOG_LEVEL}')
logging.basicConfig(level=numeric_level)
warnings.filterwarnings("ignore", category=DeprecationWarning,)
tools = [move_and_pic]
def start():
while True:
cycle_id = uuid.uuid4().hex
RobotContext.set_cycle_id(cycle_id)
logging.info("-------------------------------------------------------")
logging.info("-----------------Entering main loop--------------------")
logging.info("-------------------------------------------------------")
logging.info("Capturing image...")
base64_image = capture_image_from_ip_camera(cycle_id=cycle_id)
if base64_image:
time.sleep(1)
try:
# calling vision
message_with_goal = image_to_text(base64_image, prompt_system, prompt_user)
logging.info(f"First Image description result and goal for cycle {cycle_id}: {message_with_goal}")
if SPEECH_ENABLED:
logging.info("Generating speech from text...")
result_transformed = text_to_text(message_with_goal)
content = result_transformed.choices[0].message.content
audio = text_to_speech(content)
play_audio_with_pygame(audio)
logging.info("Speech played successfully.")
else:
logging.info("Speech is disabled. Skipping speech synthesis.")
goal_agent(message_with_goal)
except Exception as e:
logging.error(f"An error occurred during the main loop: {e}")
else:
logging.warning("No image captured. Skipping this cycle.")
# Wait CAPTURE_INTERVAL_SECONDS seconds before the next capture
logging.info(f"Sleeping {CAPTURE_INTERVAL_SECONDS} seconds before the next capture...")
time.sleep(CAPTURE_INTERVAL_SECONDS)
if __name__ == '__main__':
logging.info('Robot Alive project')
logger = logging.getLogger(__name__)
start()