-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
269 lines (229 loc) · 8.45 KB
/
app.py
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import streamlit as st
from connection import Connection
import random
import time
from utils import get_tags_list
# ip='172.16.35.227' # questacon ip
# Play an animation
def animation(button_name):
try:
st.session_state.behavior_mng_service.stopAllBehaviors()
st.session_state.behavior_mng_service.startBehavior("questacon/"+button_name)
except RuntimeError as e:
st.error(f"Got runtime error as: {e}\nTry to reconnect")
# Function to play a random animation
def play_random_animation():
animations = ["space_and_time", "self_and_others", "affirmation","exclamation","enumeration"]
selected_animation = random.choice(animations)
animation(selected_animation) # Call your animation function here
time.sleep(st.session_state.anim_time) # Wait for few seconds
def pepper_reconnect(ip,port=9559):
st.session_state.pepper = Connection()
st.session_state.session = st.session_state.pepper.connect(ip, port)
# Create a proxy to the AL services
st.session_state.behavior_mng_service = st.session_state.session.service("ALBehaviorManager")
def set_line_count():
st.session_state.line_count=int(st.session_state.line_value)-1
#creating the connection
if 'pepper' not in st.session_state:
st.session_state.pepper = Connection()
# st.session_state.ip='localhost'
# st.session_state.ip='127.0.0.1'
# port=39673
# st.session_state.ip='10.0.0.244'
st.session_state.ip='172.16.35.227' # questacon ip
# st.session_state.ip='172.20.10.4'
# st.session_state.ip='192.168.254.40'
port=9559
st.session_state.session = st.session_state.pepper.connect(st.session_state.ip, port)
# Create a proxy to the AL services
st.session_state.behavior_mng_service = st.session_state.session.service("ALBehaviorManager")
# Sleep button behaviour
st.session_state.sleep_state=0
# speaking button behavior
st.session_state.speaking=0
st.session_state.start_time=0
# Script button behavior
st.session_state.tag_list=get_tags_list()
# st.session_state.line_count=len(st.session_state.tag_list)-1
st.session_state.line_count=0
# st.session_state.line_value=0
st.session_state.anim_time=1.2 #single animation play time
# UI layout
st.markdown("<h1 style='text-align: center;'>Questacon App</h1>", unsafe_allow_html=True)
col1, col2 = st.columns([3,1])
with col1:
st.header("Interactive Actions with Pepper")
st.text("Click any button below to see Pepper in action:")
with col2:
st.write("")
st.write("")
if st.button("Sleep"):
st.session_state.sleep_state=1
animation('sleep')
if st.button("\nStop Animation\n", type="primary"): # Create the button
st.session_state.behavior_mng_service.stopAllBehaviors()
st.session_state.sleep_state=0
animation("stand")
# st.success("Button pressed...")
# Apply CSS to ensure buttons have the same width
st.markdown("""
<style>
.stButton button {
width: 100%;
margin-bottom: 10px;
}
</style>
""", unsafe_allow_html=True)
st.subheader("Eyes")
col1, col2, col3 = st.columns(3)
with col1:
if st.button("Red"):
animation("eyes_red")
with col2:
if st.button("Green"):
animation("eyes_green")
with col3:
if st.button("Normal"):
animation("eyes")
st.subheader("Dialog Animations")
# Create two columns for the 7 buttons
col1, col2 = st.columns(2)
with col1:
if st.button("Space & time"):
animation("space_and_time")
# st.success("Button pressed...")
if st.button("Self & others"):
animation("self_and_others")
# st.success("Button pressed...")
if st.button("Affirmation"):
animation("affirmation")
# st.success("Button pressed...")
if st.button("Negation"):
animation("negation")
# st.success("Button pressed...")
with col2:
if st.button("Question"):
animation("question")
# st.success("Button pressed...")
if st.button("Exclamation"):
animation("exclamation")
# st.success("Button pressed...")
if st.button("Enumeration"):
animation("enumeration")
# st.success("Button pressed...")
if st.button("Facepalm"):
animation("facepalm")
st.subheader("Moods")
# Create two columns for the 9 buttons
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("<h3 style='text-align: center;'>Positive</h3>", unsafe_allow_html=True)
if st.button("Happy"):
animation("happy")
# st.success("Button pressed...")
if st.button("Kisses"):
animation("kisses")
# st.success("Button pressed...")
if st.button("Excited"):
animation("excited")
# st.success("Button pressed...")
if st.button("Wave"):
animation('wave')
with col2:
st.markdown("<h3 style='text-align: center;'>Neutral</h3>", unsafe_allow_html=True)
if st.button("Thinking"):
animation("thinking")
# st.success("Button pressed...")
if st.button("Curious"):
animation("curious")
# st.success("Button pressed...")
if st.button("Chill"):
animation("chill")
# st.success("Button pressed...")
with col3:
st.markdown("<h3 style='text-align: center;'>Negative</h3>", unsafe_allow_html=True)
if st.button("Fear"):
animation("fear")
# st.success("Button pressed...")
if st.button("Confused"):
animation("confused")
# st.success("Button pressed...")
if st.button("Bored"):
animation("bored")
# st.success("Button pressed...")
st.subheader("Pepper Speaking")
col1, col2 = st.columns(2)
with col1:
#only 2 min speach.
# if st.button("Start Speaking"):
# st.session_state.speaking=1
# while(st.session_state.speaking==1):
# play_random_animation()
if st.button("Start Speaking"):
st.session_state.speaking = 1
st.session_state.start_time = time.time() # Record the start time
while st.session_state.speaking == 1:
play_random_animation()
if time.time() - st.session_state.start_time > 120: # Stop after 2 minutes
st.session_state.speaking = 0
st.session_state.start_time=0
animation("stand")
break
with col2:
if st.button("Stop Speaking"):
st.session_state.speaking=0
animation("stand")
st.subheader("Script")
col1, col2, col3 = st.columns(3)
eyes_tags=['eyes_green','eyes_red', 'eyes']
with col1:
if st.button("Next"):
for tag in st.session_state.tag_list[st.session_state.line_count]:
animation(tag)
if tag in eyes_tags:
continue
time.sleep(st.session_state.anim_time)
st.session_state.line_count+=1
st.success("Line No: "+str(st.session_state.line_count))
if st.session_state.line_count==28:
st.session_state.line_count=0
if st.button("Transition"):
animation('transition')
with col3:
if st.button("Go to first"):
st.session_state.line_count=0
for tag in st.session_state.tag_list[st.session_state.line_count]:
animation(tag)
if tag in eyes_tags:
continue
time.sleep(st.session_state.anim_time)
st.session_state.line_count+=1
st.success("Line No: "+str(st.session_state.line_count))
if st.button("Previous"):
st.session_state.line_count-=1
if(st.session_state.line_count<0):
st.session_state.line_count=len(st.session_state.tag_list)-1
for tag in st.session_state.tag_list[st.session_state.line_count]:
animation(tag)
if tag in eyes_tags:
continue
time.sleep(st.session_state.anim_time)
st.success("Line No: "+str(st.session_state.line_count+1))
if st.button("Reset"):
st.session_state.line_count=0
st.success("Reset to 1st")
st.subheader("Reconnect")
col1, col2 = st.columns([3,1])
with col1:
ip_value = st.text_input("Ip:", key='ip_value',value=st.session_state.ip)
port_value = st.text_input("Port:", value=9559,key='port_value', max_chars=5)
line_value = st.text_input("Line:", value=st.session_state.line_count,key='line_value', max_chars=2,on_change=set_line_count)
with col2:
st.write("")
st.write("")
st.write("")
if st.button("Reconnect"):
pepper_reconnect(ip_value,port_value)
st.session_state.line_count=st.session_state.line_value
# st.session_state.port_value = '9559'