-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpepper_api.py
More file actions
1328 lines (1191 loc) Β· 52 KB
/
pepper_api.py
File metadata and controls
1328 lines (1191 loc) Β· 52 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
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
pepper_api.py β Pepper robot control for ShopMate-R.
Pepper is the stationary humanoid at the store entrance. It greets
customers, holds the conversation, uses expressive hand gestures while
talking, shows product cards on its tablet, and says goodbye when the
interaction ends.
There is NO mock mode β this module always tries to drive the real
Pepper over SSH. If the connection drops at runtime, individual calls
log the error and continue rather than crashing the whole app.
Tablet visuals follow a single Apple-inspired glassmorphism system
defined in `_UI_CSS_BASE`, `_CAT_COLORS`, `_CAT_SVG`, and `_AURORA_BG`
below. Every screen pulls from those tokens so all views feel like
one product.
"""
import random
import config
from pypepper_ssh import PepperRobotSSH
# -------------------------------------------------------------------------
# Connect to the real Pepper once at import time. (DO NOT MODIFY.)
# -------------------------------------------------------------------------
_pepper = PepperRobotSSH(ip=config.PEPPER_IP)
# =========================================================================
# DESIGN TOKENS β Apple-style glassmorphism
# =========================================================================
# Pepper's tablet runs a Chromium-based Android WebView on recent
# firmware and supports `backdrop-filter`. For older WebViews we also
# emit `-webkit-backdrop-filter` and keep the translucent background
# opaque enough that cards still read clearly even if blur is missing.
_UI_CSS_BASE = """
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display',
'SF Pro Text', 'Roboto', 'Segoe UI',
'Helvetica Neue', Arial, sans-serif;
color: #1c1c1e;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
line-height: 1.4;
letter-spacing: -0.01em;
}
"""
# Apple-inspired vivid palette (close to SF Symbols accent hues).
_CAT_COLORS = {
"dairy": {"base": "#0A84FF", "container": "#CCE5FF", "on": "#003D80"},
"milk": {"base": "#30B0C7", "container": "#CFF2F7", "on": "#0F5869"},
"bakery": {"base": "#FF9F0A", "container": "#FFE5B8", "on": "#8A4F00"},
"produce": {"base": "#34C759", "container": "#CBEFD3", "on": "#0F5D23"},
"beverages": {"base": "#AF52DE", "container": "#ECD6F7", "on": "#4C1F73"},
"pantry": {"base": "#FF6B35", "container": "#FFD3BD", "on": "#7A2A07"},
"snacks": {"base": "#FF375F", "container": "#FFC9D4", "on": "#7A0D27"},
"frozen": {"base": "#5AC8FA", "container": "#D1EFFC", "on": "#0B5878"},
}
_CAT_DEFAULT = {"base": "#8E8E93", "container": "#E5E5EA", "on": "#3A3A3C"}
_CAT_SVG = {
"dairy": '<svg viewBox="0 0 24 24" fill="none" stroke="{c}" stroke-width="2" stroke-linecap="round"><ellipse cx="12" cy="12" rx="8" ry="9"/><path d="M8 8c1 2 5 2 8 0"/><path d="M9 14c.5 1 4.5 1 6 0"/></svg>',
"milk": '<svg viewBox="0 0 24 24" fill="none" stroke="{c}" stroke-width="2" stroke-linecap="round"><path d="M8 2h8v4l2 3v11a2 2 0 01-2 2H8a2 2 0 01-2-2V9l2-3V2z"/><path d="M6 9h12"/></svg>',
"bakery": '<svg viewBox="0 0 24 24" fill="none" stroke="{c}" stroke-width="2" stroke-linecap="round"><path d="M5 18h14a2 2 0 002-2c0-2-3-3-3-6 0-2-1-4-4-4h-4c-3 0-4 2-4 4 0 3-3 4-3 6a2 2 0 002 2z"/><path d="M9 18v2a1 1 0 001 1h4a1 1 0 001-1v-2"/></svg>',
"produce": '<svg viewBox="0 0 24 24" fill="none" stroke="{c}" stroke-width="2" stroke-linecap="round"><circle cx="12" cy="14" r="7"/><path d="M12 7V3"/><path d="M15 5c-1 1-3 1.5-5 .5"/></svg>',
"beverages": '<svg viewBox="0 0 24 24" fill="none" stroke="{c}" stroke-width="2" stroke-linecap="round"><path d="M18 8h1a4 4 0 010 8h-1"/><path d="M2 8h16v9a4 4 0 01-4 4H6a4 4 0 01-4-4V8z"/><path d="M6 1v3"/><path d="M10 1v3"/><path d="M14 1v3"/></svg>',
"pantry": '<svg viewBox="0 0 24 24" fill="none" stroke="{c}" stroke-width="2" stroke-linecap="round"><path d="M6 2L3 6v14a2 2 0 002 2h14a2 2 0 002-2V6l-3-4H6z"/><path d="M3 6h18"/><path d="M16 10a4 4 0 01-8 0"/></svg>',
"snacks": '<svg viewBox="0 0 24 24" fill="none" stroke="{c}" stroke-width="2" stroke-linecap="round"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="M3 12h18"/><path d="M9 4v16"/><path d="M15 4v16"/></svg>',
"frozen": '<svg viewBox="0 0 24 24" fill="none" stroke="{c}" stroke-width="2" stroke-linecap="round"><path d="M12 2v20M2 12h20"/><path d="M20 16l-4-4 4-4"/><path d="M4 8l4 4-4 4"/><path d="M16 4l-4 4-4-4"/><path d="M8 20l4-4 4 4"/></svg>',
}
def _cat(category: str) -> dict:
return _CAT_COLORS.get((category or "").lower(), _CAT_DEFAULT)
def _icon(category: str, color: str = None) -> str:
tpl = _CAT_SVG.get((category or "").lower(), _CAT_SVG["pantry"])
return tpl.replace("{c}", color or _cat(category)["base"])
# Vibrant multi-light aurora backdrop β the thing that makes the glass
# actually feel like glass. Used behind every dark-mode screen.
_AURORA_BG = """
background:
radial-gradient(1200px 800px at 10% 10%,
rgba(175, 82, 222, 0.45) 0%, transparent 55%),
radial-gradient(1000px 700px at 95% 20%,
rgba(10, 132, 255, 0.50) 0%, transparent 55%),
radial-gradient(900px 700px at 20% 100%,
rgba(255, 55, 95, 0.40) 0%, transparent 55%),
radial-gradient(900px 700px at 100% 100%,
rgba(255, 159, 10, 0.35) 0%, transparent 55%),
linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f0f23 100%);
"""
# =========================================================================
# SPEECH
# =========================================================================
def pepper_say(text: str, gesture: bool = True):
print(f"π€ Pepper says: {text}")
try:
if gesture:
pepper_talk_gesture()
_pepper.say(text)
except Exception as e:
print(f"[pepper_api] say() failed: {e}")
def pepper_set_volume(level: int):
try:
_pepper.set_system_volume(level)
except Exception as e:
print(f"[pepper_api] set_volume failed: {e}")
# =========================================================================
# HAND GESTURES
# =========================================================================
TALK_GESTURES = [
"animations/Stand/Gestures/Explain_1",
"animations/Stand/Gestures/Explain_2",
"animations/Stand/Gestures/Explain_3",
"animations/Stand/Gestures/Explain_4",
"animations/Stand/Gestures/Explain_8",
"animations/Stand/Gestures/Enthusiastic_4",
"animations/Stand/Gestures/Enthusiastic_5",
"animations/Stand/Gestures/YouKnowWhat_1",
"animations/Stand/Gestures/YouKnowWhat_3",
]
def pepper_gesture(path: str, wait: bool = False):
print(f"π Pepper gesture: {path}")
try:
_pepper.play_animation(path, wait=wait)
except Exception as e:
print(f"[pepper_api] gesture failed: {e}")
def pepper_talk_gesture():
pepper_gesture(random.choice(TALK_GESTURES))
def pepper_wave_hello(wait: bool = False):
pepper_gesture("animations/Stand/Gestures/Hey_1", wait=wait)
def pepper_wave_goodbye(wait: bool = False):
"""Actual goodbye wave β Bye_1, not the previous BowShort_1."""
pepper_gesture("animations/Stand/Gestures/Bye_1", wait=wait)
def pepper_bow():
pepper_gesture("animations/Stand/Gestures/BowShort_1")
def pepper_point_to_aisle():
"""Forward/lateral point (Show_1), not the upward ShowSky_1."""
pepper_gesture("animations/Stand/Gestures/Show_1")
def pepper_raise_hands():
pepper_gesture("animations/Stand/Gestures/Enthusiastic_4")
def pepper_thinking():
pepper_gesture("animations/Stand/Gestures/Thinking_1")
def pepper_nod_yes():
pepper_gesture("animations/Stand/Gestures/Yes_1")
# =========================================================================
# DISPLAY MODE β tablet output
# =========================================================================
def _display_enabled() -> bool:
return config.DISPLAY_MODE and config.PEPPER_DISPLAY_MODE
def pepper_show_image(url: str):
if not _display_enabled():
print("π΅ Pepper display mode OFF β skipping show_image")
return
print(f"πΊ Pepper tablet shows image: {url}")
try:
_pepper.show_image(url)
except Exception as e:
print(f"[pepper_api] show_image failed: {e}")
def pepper_show_product(product: dict):
if not _display_enabled():
print(f"π΅ Pepper display mode OFF β would have shown {product.get('name')}")
return
label = f"{product.get('name')} β β¬{product.get('price'):.2f} β {product.get('aisle','?')}"
print(f"πΊ Pepper tablet shows product card:\n {label}")
try:
html = _product_card_html(product)
_pepper.show_html(html)
except Exception as e:
print(f"[pepper_api] show_product failed: {e}")
def _stock_pill(stock) -> tuple:
try:
n = int(stock)
except (TypeError, ValueError):
n = 0
if n > 10:
return (f"{n} in stock", "rgba(52,199,89,0.18)", "#1E7A3A")
if n > 0:
return (f"Only {n} left", "rgba(255,149,0,0.18)", "#8A4B00")
return ("Out of stock", "rgba(255,59,48,0.18)", "#8A1A13")
# -------------------------------------------------------------------------
# SINGLE PRODUCT CARD (glass, light)
# -------------------------------------------------------------------------
def _product_card_html(product: dict) -> str:
name = product.get("name", "Item")
price = product.get("price", 0)
aisle = product.get("aisle", "?").replace("_", " ").title()
stock = product.get("stock", "?")
category = (product.get("category") or "pantry").lower()
swatch = _cat(category)
svg = _icon(category, swatch["base"])
pill_label, pill_bg, pill_fg = _stock_pill(stock)
return f"""<!DOCTYPE html>
<html><head><meta charset="utf-8">
<style>
{_UI_CSS_BASE}
body {{
{_AURORA_BG}
display: flex; align-items: center; justify-content: center;
padding: 24px;
}}
.card {{
width: 100%; max-width: 560px;
padding: 40px 44px;
text-align: center;
border-radius: 32px;
background: rgba(255,255,255,0.72);
-webkit-backdrop-filter: blur(30px) saturate(200%);
backdrop-filter: blur(30px) saturate(200%);
border: 1px solid rgba(255,255,255,0.85);
box-shadow:
0 1px 0 rgba(255,255,255,0.9) inset,
0 -1px 0 rgba(255,255,255,0.3) inset,
0 16px 40px rgba(16,24,40,0.18),
0 32px 80px rgba(16,24,40,0.14);
position: relative; overflow: hidden;
}}
.card::before {{
content: ""; position: absolute; top: 0; right: 0; left: 0; height: 5px;
background: linear-gradient(90deg, {swatch['base']} 0%, {swatch['on']} 100%);
opacity: 0.95;
}}
.icon-wrap {{
width: 108px; height: 108px;
margin: 14px auto 24px;
border-radius: 28px;
background: linear-gradient(135deg, {swatch['container']} 0%, rgba(255,255,255,0.6) 100%);
border: 1px solid rgba(255,255,255,0.8);
display: flex; align-items: center; justify-content: center;
box-shadow:
0 1px 0 rgba(255,255,255,0.9) inset,
0 8px 24px {swatch['base']}33;
}}
.icon-wrap svg {{ width: 56px; height: 56px; }}
.tag {{
display: inline-block;
padding: 6px 14px; border-radius: 999px;
background: rgba(255,255,255,0.6);
-webkit-backdrop-filter: blur(12px);
backdrop-filter: blur(12px);
border: 1px solid rgba(255,255,255,0.8);
color: {swatch['on']};
font-size: 11px; font-weight: 700;
text-transform: uppercase; letter-spacing: 1.6px;
margin-bottom: 16px;
}}
.name {{ font-size: 32px; font-weight: 700; color: #1c1c1e;
margin-bottom: 24px; letter-spacing: -0.8px; line-height: 1.1; }}
.price {{ font-size: 60px; font-weight: 700; color: #1c1c1e;
letter-spacing: -2px; line-height: 1; margin-bottom: 8px; }}
.price .cur {{ font-size: 22px; vertical-align: top; color: #8E8E93;
margin-right: 6px; font-weight: 600; }}
.meta {{ display: -webkit-flex; display: flex; -webkit-justify-content: center; justify-content: center; margin: 26px 0 22px; }}
.meta > * + * {{ margin-left: 10px; }}
.chip {{
display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
padding: 10px 18px; border-radius: 999px;
background: rgba(255,255,255,0.5);
-webkit-backdrop-filter: blur(14px);
backdrop-filter: blur(14px);
border: 1px solid rgba(255,255,255,0.8);
color: #1c1c1e; font-size: 14px; font-weight: 600;
}}
.chip svg {{ width: 16px; height: 16px; stroke: {swatch['base']}; margin-right: 8px; }}
.pill {{
display: inline-block;
padding: 10px 24px; border-radius: 999px;
background: {pill_bg};
-webkit-backdrop-filter: blur(12px);
backdrop-filter: blur(12px);
border: 1px solid rgba(255,255,255,0.4);
color: {pill_fg};
font-size: 14px; font-weight: 700; letter-spacing: 0.3px;
}}
</style></head><body>
<div class="card">
<div class="icon-wrap">{svg}</div>
<div class="tag">{category.title()}</div>
<div class="name">{name}</div>
<div class="price"><span class="cur">EUR</span>{price:.2f}</div>
<div class="meta">
<div class="chip">
<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0118 0z"/><circle cx="12" cy="10" r="3"/>
</svg>
<span>{aisle}</span>
</div>
<div class="chip">
<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M20 7l-8-4-8 4v10l8 4 8-4V7z"/><path d="M4 7l8 4 8-4"/><path d="M12 11v10"/>
</svg>
<span>{stock} units</span>
</div>
</div>
<div class="pill">{pill_label}</div>
</div>
</body></html>"""
# -------------------------------------------------------------------------
# WELCOME (glass on aurora)
# -------------------------------------------------------------------------
def pepper_show_welcome():
if not _display_enabled(): return
print("πΊ Pepper tablet shows welcome screen")
html = f"""<!DOCTYPE html><html><head><meta charset="utf-8">
<style>
{_UI_CSS_BASE}
@keyframes floaty {{ 0%,100%{{transform:translateY(0);}} 50%{{transform:translateY(-10px);}} }}
body {{
{_AURORA_BG}
color: #fff;
display: flex; align-items: center; justify-content: center;
}}
.card {{
text-align: center; padding: 56px 72px; max-width: 680px;
border-radius: 40px;
background: rgba(255,255,255,0.12);
-webkit-backdrop-filter: blur(40px) saturate(180%);
backdrop-filter: blur(40px) saturate(180%);
border: 1px solid rgba(255,255,255,0.22);
box-shadow:
0 1px 0 rgba(255,255,255,0.3) inset,
0 20px 50px rgba(0,0,0,0.35),
0 40px 100px rgba(0,0,0,0.25);
}}
.mark {{
width: 112px; height: 112px;
background: rgba(255,255,255,0.18);
-webkit-backdrop-filter: blur(20px);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.35);
border-radius: 32px;
display: flex; align-items: center; justify-content: center;
margin: 0 auto 32px;
animation: floaty 4s ease-in-out infinite;
box-shadow: 0 1px 0 rgba(255,255,255,0.4) inset, 0 16px 40px rgba(0,0,0,0.3);
}}
.mark svg {{ width: 56px; height: 56px; stroke: #fff; }}
.brand {{
font-size: 13px; font-weight: 700; letter-spacing: 4px;
text-transform: uppercase; color: rgba(255,255,255,0.78);
margin-bottom: 16px;
}}
.title {{ font-size: 64px; font-weight: 700; margin-bottom: 14px;
letter-spacing: -2px; line-height: 1.05; }}
.subtitle {{ font-size: 22px; font-weight: 400;
color: rgba(255,255,255,0.88); margin-bottom: 32px; }}
.chips {{ display: -webkit-flex; display: flex; -webkit-justify-content: center; justify-content: center; -webkit-flex-wrap: wrap; flex-wrap: wrap; }}
.chip {{ margin: 0 5px 10px; }}
.chip {{
padding: 10px 18px;
background: rgba(255,255,255,0.14);
-webkit-backdrop-filter: blur(16px);
backdrop-filter: blur(16px);
border: 1px solid rgba(255,255,255,0.26);
border-radius: 999px;
font-size: 14px; font-weight: 600;
color: rgba(255,255,255,0.95);
}}
</style></head><body>
<div class="card">
<div class="mark">
<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round">
<circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
<path d="M1 1h4l2.68 13.39a2 2 0 002 1.61h9.72a2 2 0 002-1.61L23 6H6"/>
</svg>
</div>
<div class="brand">ShopMate Assistant</div>
<div class="title">Welcome</div>
<div class="subtitle">How can I help you shop today?</div>
<div class="chips">
<div class="chip">Voice-guided</div>
<div class="chip">Powered by Pepper & Temi</div>
</div>
</div>
</body></html>"""
try:
_pepper.show_html(html)
except Exception as e:
print(f"[pepper_api] show_welcome failed: {e}")
# -------------------------------------------------------------------------
# GOODBYE (glass on green aurora)
# -------------------------------------------------------------------------
def pepper_show_goodbye():
if not _display_enabled(): return
print("πΊ Pepper tablet shows goodbye screen")
html = f"""<!DOCTYPE html><html><head><meta charset="utf-8">
<style>
{_UI_CSS_BASE}
body {{
background:
radial-gradient(900px 700px at 15% 15%, rgba(52,199,89,0.55) 0%, transparent 55%),
radial-gradient(900px 700px at 85% 85%, rgba(48,176,199,0.55) 0%, transparent 55%),
radial-gradient(700px 500px at 50% 50%, rgba(10,132,255,0.30) 0%, transparent 55%),
linear-gradient(135deg, #0a3d2e 0%, #0b2a3b 50%, #062632 100%);
color: #fff;
display: flex; align-items: center; justify-content: center;
}}
.card {{
text-align: center; padding: 56px 72px; max-width: 640px;
border-radius: 40px;
background: rgba(255,255,255,0.14);
-webkit-backdrop-filter: blur(40px) saturate(180%);
backdrop-filter: blur(40px) saturate(180%);
border: 1px solid rgba(255,255,255,0.24);
box-shadow:
0 1px 0 rgba(255,255,255,0.3) inset,
0 20px 50px rgba(0,0,0,0.35),
0 40px 100px rgba(0,0,0,0.22);
}}
.mark {{
width: 112px; height: 112px;
background: rgba(255,255,255,0.2);
-webkit-backdrop-filter: blur(20px);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.38);
border-radius: 32px;
display: flex; align-items: center; justify-content: center;
margin: 0 auto 32px;
box-shadow: 0 1px 0 rgba(255,255,255,0.45) inset, 0 16px 40px rgba(0,0,0,0.3);
}}
.mark svg {{ width: 56px; height: 56px; stroke: #fff; }}
.brand {{
font-size: 13px; font-weight: 700; letter-spacing: 4px;
text-transform: uppercase; color: rgba(255,255,255,0.78);
margin-bottom: 16px;
}}
.title {{ font-size: 64px; font-weight: 700; margin-bottom: 14px;
letter-spacing: -2px; }}
.subtitle {{ font-size: 22px; color: rgba(255,255,255,0.88);
font-weight: 400; }}
</style></head><body>
<div class="card">
<div class="mark">
<svg viewBox="0 0 24 24" fill="none" stroke-width="2.5"
stroke-linecap="round" stroke-linejoin="round">
<polyline points="20 6 9 17 4 12"/>
</svg>
</div>
<div class="brand">Thank You</div>
<div class="title">Goodbye</div>
<div class="subtitle">Have a wonderful day!</div>
</div>
</body></html>"""
try:
_pepper.show_html(html)
except Exception as e:
print(f"[pepper_api] show_goodbye failed: {e}")
# -------------------------------------------------------------------------
# IDLE (glass on aurora)
# -------------------------------------------------------------------------
def pepper_show_idle():
if not _display_enabled(): return
print("πΊ Pepper tablet shows idle screen (waiting for hello)")
html = f"""<!DOCTYPE html><html><head><meta charset="utf-8">
<style>
{_UI_CSS_BASE}
@keyframes pulse {{ 0%,100%{{transform:scale(1);opacity:1;}} 50%{{transform:scale(1.05);opacity:0.92;}} }}
@keyframes float {{ 0%,100%{{transform:translateY(0);}} 50%{{transform:translateY(-8px);}} }}
body {{
{_AURORA_BG}
color: #fff;
display: flex; align-items: center; justify-content: center;
}}
.card {{
text-align: center; padding: 56px 72px; max-width: 620px;
border-radius: 40px;
background: rgba(255,255,255,0.10);
-webkit-backdrop-filter: blur(40px) saturate(180%);
backdrop-filter: blur(40px) saturate(180%);
border: 1px solid rgba(255,255,255,0.20);
box-shadow:
0 1px 0 rgba(255,255,255,0.25) inset,
0 20px 50px rgba(0,0,0,0.4),
0 40px 100px rgba(0,0,0,0.25);
}}
.mark {{
width: 116px; height: 116px;
background: rgba(255,255,255,0.12);
-webkit-backdrop-filter: blur(20px);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.24);
border-radius: 32px;
display: flex; align-items: center; justify-content: center;
margin: 0 auto 32px;
animation: float 3.2s ease-in-out infinite;
box-shadow: 0 1px 0 rgba(255,255,255,0.3) inset, 0 16px 40px rgba(0,0,0,0.35);
}}
.mark svg {{ width: 56px; height: 56px; stroke: #FFB340; }}
.brand {{
font-size: 13px; font-weight: 700; letter-spacing: 4px;
text-transform: uppercase; color: rgba(255,255,255,0.65);
margin-bottom: 16px;
}}
.title {{ font-size: 54px; font-weight: 700; margin-bottom: 14px;
letter-spacing: -1.5px; color: #fff; }}
.subtitle {{ font-size: 20px; color: rgba(255,255,255,0.75);
font-weight: 400; margin-bottom: 36px; }}
.cta {{
display: inline-block; padding: 14px 32px;
border-radius: 999px;
background: linear-gradient(135deg, #FFB340 0%, #FF6B35 100%);
color: #1a1a2e;
font-size: 16px; font-weight: 700; letter-spacing: 0.4px;
animation: pulse 2.6s ease-in-out infinite;
border: 1px solid rgba(255,255,255,0.3);
box-shadow: 0 1px 0 rgba(255,255,255,0.5) inset, 0 8px 24px rgba(255,107,53,0.4);
}}
</style></head><body>
<div class="card">
<div class="mark">
<svg viewBox="0 0 24 24" fill="none" stroke-width="1.8"
stroke-linecap="round" stroke-linejoin="round">
<path d="M7 11V7a5 5 0 0110 0v4"/>
<path d="M4 15.5C4 12.5 6 11 8 11h8c2 0 4 1.5 4 4.5 0 4-3 7.5-8 7.5s-8-3.5-8-7.5z"/>
<path d="M16 11V5a2 2 0 00-4 0"/>
<path d="M12 11V4a2 2 0 00-4 0v7"/>
</svg>
</div>
<div class="brand">ShopMate Assistant</div>
<div class="title">Ready to help</div>
<div class="subtitle">Your personal grocery assistant</div>
<div class="cta">Wave or say “Hello” to begin</div>
</div>
</body></html>"""
try:
_pepper.show_html(html)
except Exception as e:
print(f"[pepper_api] show_idle failed: {e}")
# -------------------------------------------------------------------------
# CATEGORIES DASHBOARD β 2 columns Γ rich glass tiles
# -------------------------------------------------------------------------
def pepper_show_categories():
"""Category dashboard with a 2-column glass-tile grid. Each tile
shows the category header plus a 2-column mini-preview of its
products so the customer sees options at a glance."""
if not _display_enabled(): return
print("πΊ Pepper tablet shows product category dashboard")
from grocery_db import get_all_items
items = get_all_items()
cats: dict[str, list] = {}
for it in items:
cats.setdefault(it["category"], []).append(it)
tiles_html = ""
for cat_name, products in cats.items():
sw = _cat(cat_name)
icon = _icon(cat_name, "#ffffff")
in_stock = sum(1 for p in products if p["stock"] > 0)
# Preview up to 4 products β fills the 2Γ2 sub-grid nicely
preview = sorted(products, key=lambda p: -p["stock"])[:4]
preview_html = ""
for p in preview:
is_out = p["stock"] <= 0
preview_html += f'''
<div class="mini{' out' if is_out else ''}">
<div class="mini-name">{p["name"]}</div>
<div class="mini-price">β¬{p["price"]:.2f}</div>
</div>'''
extra = len(products) - len(preview)
more_html = (f'<div class="more">+{extra} more</div>'
if extra > 0 else "")
tiles_html += f'''
<div class="tile">
<div class="tile-bar" style="background: linear-gradient(90deg, {sw['base']} 0%, {sw['on']} 100%);"></div>
<div class="tile-head">
<div class="t-icon" style="background: linear-gradient(135deg, {sw['base']} 0%, {sw['on']} 100%);">{icon}</div>
<div>
<div class="t-name">{cat_name.title()}</div>
<div class="t-count">{in_stock} of {len(products)} in stock</div>
</div>
</div>
<div class="mini-grid">
{preview_html}
</div>
{more_html}
</div>'''
html = f'''<!DOCTYPE html><html><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
{_UI_CSS_BASE}
body {{
{_AURORA_BG}
padding: 20px 24px;
color: #fff;
}}
/* ---- Top bar ---- */
.topbar {{
display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
-webkit-justify-content: space-between; justify-content: space-between;
padding: 14px 20px;
border-radius: 20px; margin-bottom: 18px;
background: rgba(255,255,255,0.12);
-webkit-backdrop-filter: blur(28px) saturate(180%);
backdrop-filter: blur(28px) saturate(180%);
border: 1px solid rgba(255,255,255,0.22);
box-shadow: 0 1px 0 rgba(255,255,255,0.3) inset, 0 8px 24px rgba(0,0,0,0.2);
}}
.logo {{ display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; }}
.logo > * + * {{ margin-left: 14px; }}
.logo-mark {{
width: 44px; height: 44px;
background: linear-gradient(135deg, #AF52DE 0%, #FF375F 100%);
border-radius: 14px;
border: 1px solid rgba(255,255,255,0.3);
display: flex; align-items: center; justify-content: center;
box-shadow: 0 1px 0 rgba(255,255,255,0.4) inset, 0 8px 20px rgba(175,82,222,0.4);
}}
.logo-mark svg {{ width: 22px; height: 22px; stroke: #fff; }}
.logo-text {{ font-size: 20px; font-weight: 700; color: #fff;
letter-spacing: -0.3px; line-height: 1.1; }}
.logo-sub {{ font-size: 11px; font-weight: 700; color: rgba(255,255,255,0.7);
text-transform: uppercase; letter-spacing: 1.4px; margin-top: 2px; }}
.search {{ flex: 1; max-width: 380px; position: relative; }}
.search svg {{ position: absolute; left: 16px; top: 50%;
transform: translateY(-50%); width: 18px; height: 18px;
stroke: rgba(255,255,255,0.6); }}
.search input {{
width: 100%; padding: 11px 16px 11px 44px;
border: 1px solid rgba(255,255,255,0.25); border-radius: 999px;
background: rgba(255,255,255,0.1);
-webkit-backdrop-filter: blur(16px);
backdrop-filter: blur(16px);
color: #fff; font-size: 15px; font-weight: 500; outline: none;
}}
.search input::placeholder {{ color: rgba(255,255,255,0.55); }}
.status {{
display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
padding: 6px 14px;
background: rgba(52,199,89,0.2);
border: 1px solid rgba(52,199,89,0.4);
color: #6EEA90; border-radius: 999px;
font-size: 12px; font-weight: 700;
}}
.status-dot {{ width: 8px; height: 8px; border-radius: 50%;
background: #34C759; box-shadow: 0 0 0 3px rgba(52,199,89,0.25);
margin-right: 8px; }}
/* ---- Hint banner ---- */
.banner {{
padding: 14px 20px; border-radius: 18px; margin-bottom: 18px;
display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
background: rgba(255,255,255,0.10);
-webkit-backdrop-filter: blur(24px) saturate(180%);
backdrop-filter: blur(24px) saturate(180%);
border: 1px solid rgba(255,255,255,0.18);
box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset;
}}
.banner-ic {{
width: 38px; height: 38px; flex-shrink: 0;
background: linear-gradient(135deg, #FFB340 0%, #FF6B35 100%);
border-radius: 12px;
border: 1px solid rgba(255,255,255,0.3);
display: flex; align-items: center; justify-content: center;
box-shadow: 0 1px 0 rgba(255,255,255,0.4) inset, 0 4px 12px rgba(255,107,53,0.35);
}}
.banner-ic svg {{ width: 20px; height: 20px; stroke: #fff; }}
.banner-ic {{ margin-right: 14px; }}
.banner-text {{ font-size: 15px; color: rgba(255,255,255,0.95); }}
.banner-text strong {{ color: #fff; font-weight: 700; }}
/* ---- 2-column category grid ---- */
.section-title {{
font-size: 12px; font-weight: 700;
color: rgba(255,255,255,0.65); text-transform: uppercase;
letter-spacing: 1.8px; margin-bottom: 12px; padding-left: 4px;
}}
.grid {{
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}}
.tile {{
width: 48.5%;
margin-right: 3%;
margin-bottom: 14px;
border-radius: 22px;
padding: 18px 18px 16px;
position: relative; overflow: hidden;
background: rgba(255,255,255,0.14);
-webkit-backdrop-filter: blur(26px) saturate(180%);
backdrop-filter: blur(26px) saturate(180%);
border: 1px solid rgba(255,255,255,0.22);
box-shadow:
0 1px 0 rgba(255,255,255,0.3) inset,
0 8px 24px rgba(0,0,0,0.2),
0 16px 40px rgba(0,0,0,0.12);
}}
.tile:nth-child(2n) {{ margin-right: 0; }}
.tile-bar {{
position: absolute; top: 0; right: 0; left: 0; height: 3px;
border-radius: 22px 22px 0 0; opacity: 0.9;
}}
.tile-head {{
display: -webkit-flex; display: flex;
-webkit-align-items: center; align-items: center;
margin-bottom: 12px;
}}
.tile-head > *:first-child {{ margin-right: 12px; }}
.t-icon {{
width: 48px; height: 48px;
-webkit-flex-shrink: 0; flex-shrink: 0;
border: 1px solid rgba(255,255,255,0.3);
border-radius: 14px;
display: -webkit-flex; display: flex;
-webkit-align-items: center; align-items: center;
-webkit-justify-content: center; justify-content: center;
box-shadow: 0 1px 0 rgba(255,255,255,0.4) inset, 0 4px 10px rgba(0,0,0,0.25);
}}
.t-icon svg {{ width: 26px; height: 26px; stroke: #fff; }}
.t-name {{ font-size: 18px; font-weight: 700; color: #fff;
margin-bottom: 2px; letter-spacing: -0.3px; }}
.t-count {{ font-size: 11px; font-weight: 700; color: rgba(255,255,255,0.7);
text-transform: uppercase; letter-spacing: 1px; }}
/* ---- mini 2-col product preview inside each tile ---- */
.mini-grid {{
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}}
.mini {{
width: 48%;
margin-right: 4%;
margin-bottom: 6px;
padding: 8px 10px; border-radius: 10px;
background: rgba(255,255,255,0.12);
border: 1px solid rgba(255,255,255,0.18);
display: -webkit-flex; display: flex;
-webkit-align-items: center; align-items: center;
-webkit-justify-content: space-between; justify-content: space-between;
min-width: 0;
}}
.mini:nth-child(2n) {{ margin-right: 0; }}
.mini.out {{ opacity: 0.45; }}
.mini-name {{
font-size: 12px; font-weight: 600;
color: rgba(255,255,255,0.95);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
min-width: 0;
-webkit-flex: 1; flex: 1;
margin-right: 6px;
}}
.mini-price {{ font-size: 12px; font-weight: 700; color: #fff;
white-space: nowrap; }}
.more {{
margin-top: 8px; text-align: center;
padding: 6px 12px;
background: rgba(255,255,255,0.08);
border: 1px solid rgba(255,255,255,0.16);
border-radius: 999px;
font-size: 11px; font-weight: 700;
color: rgba(255,255,255,0.7);
text-transform: uppercase; letter-spacing: 0.8px;
}}
.footer {{ text-align: center; margin-top: 18px;
font-size: 12px; font-weight: 600;
color: rgba(255,255,255,0.55); letter-spacing: 0.4px; }}
</style></head><body>
<div class="topbar">
<div class="logo">
<div class="logo-mark">
<svg viewBox="0 0 24 24" fill="none" stroke-width="2.2" stroke-linecap="round">
<circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
<path d="M1 1h4l2.68 13.39a2 2 0 002 1.61h9.72a2 2 0 002-1.61L23 6H6"/>
</svg>
</div>
<div>
<div class="logo-text">ShopMate</div>
<div class="logo-sub">Grocery Assistant</div>
</div>
</div>
<div class="search">
<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round">
<circle cx="11" cy="11" r="8"/><path d="M21 21l-4.35-4.35"/>
</svg>
<input type="text" placeholder="Listening..." readonly>
</div>
<div class="status">
<div class="status-dot"></div>
<span>Online</span>
</div>
</div>
<div class="banner">
<div class="banner-ic">
<svg viewBox="0 0 24 24" fill="none" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round">
<path d="M12 2a3 3 0 00-3 3v7a3 3 0 006 0V5a3 3 0 00-3-3z"/>
<path d="M19 10v2a7 7 0 01-14 0v-2"/>
<line x1="12" y1="19" x2="12" y2="22"/>
</svg>
</div>
<div class="banner-text">
<strong>Tell me what you need</strong> — for example, “I need milk” or “Where are the snacks?”
</div>
</div>
<div class="section-title">Browse by category</div>
<div class="grid">{tiles_html}</div>
<div class="footer">Say “help” or “goodbye” at any time</div>
</body></html>'''
try:
_pepper.show_html(html)
except Exception as e:
print(f"[pepper_api] show_categories failed: {e}")
# -------------------------------------------------------------------------
# CATEGORY β PRODUCT GRID (2 columns)
# -------------------------------------------------------------------------
def pepper_show_category_products(category: str, products: list):
if not _display_enabled(): return
print(f"πΊ Pepper tablet shows {category} products ({len(products)} items)")
sw = _cat(category)
icon = _icon(category, "#ffffff")
rows = ""
for p in products:
pill_label, pill_bg, pill_fg = _stock_pill(p.get("stock", 0))
aisle = p["aisle"].replace("_", " ").title()
rows += f'''
<div class="product">
<div class="p-head">
<div class="p-name">{p["name"]}</div>
<div class="p-price">β¬{p["price"]:.2f}</div>
</div>
<div class="p-meta">
<div class="p-aisle">
<svg viewBox="0 0 24 24" fill="none" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round">
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0118 0z"/>
<circle cx="12" cy="10" r="3"/>
</svg>
<span>{aisle}</span>
</div>
<div class="p-stock" style="background:{pill_bg}; color:{pill_fg};">{pill_label}</div>
</div>
</div>'''
html = f'''<!DOCTYPE html><html><head><meta charset="utf-8">
<style>
{_UI_CSS_BASE}
body {{
background:
radial-gradient(1100px 800px at 10% 10%, {sw['base']}66 0%, transparent 55%),
radial-gradient(900px 700px at 90% 90%, {sw['on']}55 0%, transparent 55%),
radial-gradient(800px 600px at 50% 50%, rgba(175,82,222,0.25) 0%, transparent 55%),
linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f0f23 100%);
padding: 22px;
color: #fff;
}}
.header {{
border-radius: 24px; padding: 20px 24px; margin-bottom: 18px;
display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
position: relative; overflow: hidden;
background: rgba(255,255,255,0.14);
-webkit-backdrop-filter: blur(30px) saturate(180%);
backdrop-filter: blur(30px) saturate(180%);
border: 1px solid rgba(255,255,255,0.25);
box-shadow: 0 1px 0 rgba(255,255,255,0.35) inset, 0 12px 32px rgba(0,0,0,0.25);
}}
.header::before {{
content: ""; position: absolute; top: 0; right: 0; left: 0; height: 4px;
background: linear-gradient(90deg, {sw['base']} 0%, {sw['on']} 100%);
}}
.h-icon {{
width: 60px; height: 60px;
background: linear-gradient(135deg, {sw['base']} 0%, {sw['on']} 100%);
border-radius: 18px;
border: 1px solid rgba(255,255,255,0.3);
display: -webkit-flex; display: flex;
-webkit-align-items: center; align-items: center;
-webkit-justify-content: center; justify-content: center;
-webkit-flex-shrink: 0; flex-shrink: 0;
margin-right: 16px;
box-shadow: 0 1px 0 rgba(255,255,255,0.4) inset, 0 8px 20px {sw['base']}55;
}}
.h-icon svg {{ width: 32px; height: 32px; }}
.h-title {{ font-size: 28px; font-weight: 700; color: #fff;
letter-spacing: -0.6px; line-height: 1.1; }}
.h-sub {{ font-size: 12px; font-weight: 700; color: rgba(255,255,255,0.7);
text-transform: uppercase; letter-spacing: 1.2px; margin-top: 4px; }}
.grid {{
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}}
.product {{
width: 48.5%;
margin-right: 3%;
margin-bottom: 12px;
border-radius: 18px; padding: 16px 18px;
background: rgba(255,255,255,0.14);
-webkit-backdrop-filter: blur(24px) saturate(180%);
backdrop-filter: blur(24px) saturate(180%);
border: 1px solid rgba(255,255,255,0.22);
border-left: 3px solid {sw['base']};
box-shadow: 0 1px 0 rgba(255,255,255,0.25) inset, 0 6px 16px rgba(0,0,0,0.2);
}}
.product:nth-child(2n) {{ margin-right: 0; }}
.p-head {{ display: -webkit-flex; display: flex;
-webkit-justify-content: space-between; justify-content: space-between;
-webkit-align-items: baseline; align-items: baseline;
margin-bottom: 12px; }}
.p-name {{ margin-right: 12px; }}
.p-name {{ font-size: 17px; font-weight: 700; color: #fff; letter-spacing: -0.2px; }}
.p-price {{ font-size: 18px; font-weight: 700; color: #fff; white-space: nowrap; }}
.p-meta {{ display: -webkit-flex; display: flex;
-webkit-justify-content: space-between; justify-content: space-between;
-webkit-align-items: center; align-items: center; }}
.p-aisle {{
display: -webkit-flex; display: flex;
-webkit-align-items: center; align-items: center;
font-size: 11px; font-weight: 700;
color: rgba(255,255,255,0.7); text-transform: uppercase;
letter-spacing: 0.6px;
}}
.p-aisle svg {{ width: 13px; height: 13px; stroke: rgba(255,255,255,0.7); margin-right: 6px; }}
.p-stock {{
font-size: 11px; font-weight: 700;