-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfamily_bell.py
More file actions
151 lines (131 loc) · 4.51 KB
/
Copy pathfamily_bell.py
File metadata and controls
151 lines (131 loc) · 4.51 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from datetime import datetime
import helpers
import gpt
import random
import time
is_family_bell_active = False
current_bell_time = ""
current_step = 0
art_styles = [
"cartoon",
"realistic",
"hand drawn",
"cute picture that would look nice in a nursery",
"drawn with crayons, imperfect, with some of the colouring going outside of the lines",
"a child's drawing (simple, scribbly, cute)",
]
animal_types = [
"a dog",
"a sheep",
"a cow",
"a dinosaur",
"an animal",
]
schedule = {
"18:30": {
"title": "It's almost time for bed!",
"ending": "You're all ready for bed - enjoy your bedtime story, and good night.",
"steps": [
"Put your pyjamas on.",
"Have a lovely warm milk",
"Brush your teeth and make sure they're all nice and clean.",
],
}
}
def run_through_steps(input_text):
"""
Checks the user's input and runs through the steps
"""
global is_family_bell_active, current_bell_time, current_step
confirmation_phrases = [
"start",
"ready",
"yes",
"yeah",
"let's go",
"next",
"step",
"done",
"all done",
"finished",
"already",
"first",
"all ready",
]
negative_phrases = [
"stop",
"cancel",
]
if any(
confirmation_phrase in input_text
for confirmation_phrase in confirmation_phrases
):
helpers.play_audio("audio/epiphany.m4a")
image_prompt = f"In the following art style ({random.choice(art_styles)}), generate a fun little picture of {random.choice(animal_types)}, doing the following:"
if current_step > len(schedule[current_bell_time]["steps"]) - 1:
# Ran through all steps, reset the family bell
announcement = schedule[current_bell_time]["ending"]
image_prompt = f"{image_prompt} {schedule[current_bell_time]['ending']}"
current_step = 0
is_family_bell_active = False
current_bell_time = ""
else:
print(
f"Current step: {current_step} | Number of steps: {len(schedule[current_bell_time]['steps']) - 1}"
)
print(
f"{schedule[current_bell_time]['steps'][current_step]}"
)
image_prompt = f"{image_prompt} {schedule[current_bell_time]['steps'][current_step]}"
if current_step == 0:
announcement_start = (
"Your first step is to"
)
elif current_step == len(schedule[current_bell_time]["steps"]) - 1:
announcement_start = "Your final step is to"
else:
announcement_start = "Your next step is to"
announcement = f"{announcement_start} {schedule[current_bell_time]['steps'][current_step]}"
current_step += 1
print(image_prompt)
gpt.start_image_thread(image_prompt, "")
gpt.whisper_text_to_speech(announcement)
elif any(negative_phrase in input_text for negative_phrase in negative_phrases):
print("Stopping family bell")
gpt.whisper_text_to_speech("Stopping family bell")
# Reset the family bell
current_step = 0
is_family_bell_active = False
current_bell_time = ""
def announce_family_bell(schedule_time):
"""
Announce the family bell
"""
announcement = f"""
{schedule[schedule_time]['title']}. It looks like you have
{len(schedule[schedule_time]['steps'])} steps. Let me know when you're
ready to start, and say done when you've finished each step!
"""
gpt.whisper_text_to_speech(announcement, insert_audio_path="audio/glimpse.m4a")
def check_time():
"""
Checks the current time and updates athe family bell status
"""
global is_family_bell_active, current_bell_time
while True:
now = str(datetime.now().strftime("%H:%M"))
if any(now in schedule_time for schedule_time in schedule):
# print(f"Schedule time: {schedule_time}")
# Activate the family bell status
is_family_bell_active = True
bell = schedule[now]["title"]
current_bell_time = now
print(f"Activating family bell: {bell}")
helpers.display_image("assistant_images/family_bell.png")
announce_family_bell(now)
# else:
# is_family_bell_active = False
time.sleep(60)
if __name__ == "__main__":
gpt.setup()
check_time()