michaelmccamy commited on
Commit
28fa583
·
verified ·
1 Parent(s): 7cb34ef

Deploy backend

Browse files
Files changed (2) hide show
  1. main.py +1 -0
  2. pipeline.py +14 -6
main.py CHANGED
@@ -180,6 +180,7 @@ WALKER_PHRASES |= {f"Sure thing. Let's find the {t}." for t in pipeline.FIND_TAR
180
  # Find: keeping the target in the picture up and down. Mirrors tiltPhrase and offFramePhrase in app/App.tsx.
181
  FRAMING_PHRASES = {
182
  "Tilt the phone down a little.", "Tilt the phone up a little.",
 
183
  "It's below the camera. Tilt the phone down.", "It's above the camera. Tilt the phone up.",
184
  }
185
  GUIDE_PHRASES = (
 
180
  # Find: keeping the target in the picture up and down. Mirrors tiltPhrase and offFramePhrase in app/App.tsx.
181
  FRAMING_PHRASES = {
182
  "Tilt the phone down a little.", "Tilt the phone up a little.",
183
+ "Straight ahead.", # the moment a turn lines the user up with the target (LINED_UP_PHRASE)
184
  "It's below the camera. Tilt the phone down.", "It's above the camera. Tilt the phone up.",
185
  }
186
  GUIDE_PHRASES = (
pipeline.py CHANGED
@@ -481,15 +481,22 @@ def _find_how_far(distance: float, units: str = "meters") -> str:
481
  return f"about {meters:g} {'meter' if meters == 1 else 'meters'}"
482
 
483
 
 
 
 
 
 
 
484
  def find_sentence(
485
- target: str, direction: str | None, distance: float | None, match: str | None = None, units: str = "meters"
 
486
  ) -> str:
487
  """With a description, the sentence never repeats the user's words ("Found it", not "Red bench"),
488
  so every possible sentence can be on the /say allowlist and a cloned voice can't be made to say
489
  arbitrary text."""
490
  if direction is None or distance is None:
491
  return "No match yet. Turn slowly." if match else f"No {target} yet. Turn slowly."
492
- where = {"left": "slightly left", "right": "slightly right"}.get(direction, "ahead")
493
  name = {"yes": "Found it", "possible": "Possible match"}.get(match or "", target.capitalize())
494
  return f"{name}, {where}, {_find_how_far(distance, units)}."
495
 
@@ -500,12 +507,12 @@ def find_phrases() -> set[str]:
500
  distances = [round(0.5 + 0.05 * i, 2) for i in range(int((FIND_MAX_SPOKEN_M - 0.5) / 0.05) + 2)]
501
  phrases = {find_sentence("", None, None, "no")}
502
  for units in UNITS:
503
- for direction in ("left", "ahead", "right"):
504
  for d in distances:
505
  for target in FIND_TARGETS:
506
- phrases.add(find_sentence(target, direction, d, None, units))
507
  for match in ("yes", "possible"):
508
- phrases.add(find_sentence("", direction, d, match, units))
509
  for target in FIND_TARGETS:
510
  phrases.add(find_sentence(target, None, None))
511
  return phrases
@@ -593,7 +600,8 @@ def find(
593
  else:
594
  candidates = []
595
  target_distance = result.pop("_distance", None)
596
- result["sentence"] = find_sentence(target, result["direction"], target_distance, result["match"], units)
 
597
  for c in candidates:
598
  c.pop("_distance")
599
  result["candidates"] = candidates
 
481
  return f"about {meters:g} {'meter' if meters == 1 else 'meters'}"
482
 
483
 
484
+ # Find tells the user what to do, in two sizes: up to this many degrees off is "turn a little left",
485
+ # beyond it (out to the edge of the frame) "turn left". "Slightly left" said where the target was, not
486
+ # what to do, and gave no idea of how much. Mirrored in driftSentence() in app/App.tsx.
487
+ FIND_SMALL_TURN_DEG = 15
488
+
489
+
490
  def find_sentence(
491
+ target: str, direction: str | None, distance: float | None, match: str | None = None, units: str = "meters",
492
+ small: bool = True,
493
  ) -> str:
494
  """With a description, the sentence never repeats the user's words ("Found it", not "Red bench"),
495
  so every possible sentence can be on the /say allowlist and a cloned voice can't be made to say
496
  arbitrary text."""
497
  if direction is None or distance is None:
498
  return "No match yet. Turn slowly." if match else f"No {target} yet. Turn slowly."
499
+ where = "ahead" if direction not in ("left", "right") else f"turn a little {direction}" if small else f"turn {direction}"
500
  name = {"yes": "Found it", "possible": "Possible match"}.get(match or "", target.capitalize())
501
  return f"{name}, {where}, {_find_how_far(distance, units)}."
502
 
 
507
  distances = [round(0.5 + 0.05 * i, 2) for i in range(int((FIND_MAX_SPOKEN_M - 0.5) / 0.05) + 2)]
508
  phrases = {find_sentence("", None, None, "no")}
509
  for units in UNITS:
510
+ for direction, small in (("left", True), ("left", False), ("ahead", True), ("right", True), ("right", False)):
511
  for d in distances:
512
  for target in FIND_TARGETS:
513
+ phrases.add(find_sentence(target, direction, d, None, units, small))
514
  for match in ("yes", "possible"):
515
+ phrases.add(find_sentence("", direction, d, match, units, small))
516
  for target in FIND_TARGETS:
517
  phrases.add(find_sentence(target, None, None))
518
  return phrases
 
600
  else:
601
  candidates = []
602
  target_distance = result.pop("_distance", None)
603
+ small = result["bearing_deg"] is None or abs(result["bearing_deg"]) <= FIND_SMALL_TURN_DEG
604
+ result["sentence"] = find_sentence(target, result["direction"], target_distance, result["match"], units, small)
605
  for c in candidates:
606
  c.pop("_distance")
607
  result["candidates"] = candidates