diff --git a/live_illustrate/__main__.py b/live_illustrate/__main__.py index 11f1f88..743f3b8 100644 --- a/live_illustrate/__main__.py +++ b/live_illustrate/__main__.py @@ -80,6 +80,11 @@ def get_args() -> argparse.Namespace: type=float, help="How much of the previous transcription to retain after generating each summary. 0 - 1.0", ) + parser.add_argument( + "--oneshot", + type=argparse.FileType("r"), + help="Read transcription lines from a text file and render. Useful for testing.", + ) parser.add_argument("-v", "--verbose", action="count", default=0) return parser.parse_args() @@ -93,8 +98,11 @@ def main() -> None: logging.getLogger("requests").setLevel(logging.INFO if args.verbose > 0 else logging.WARNING) logging.getLogger("werkzeug").setLevel(logging.INFO if args.verbose > 0 else logging.WARNING) # flask - # create each of our thread objects with the apppropriate command line args - transcriber = AudioTranscriber(model=args.audio_model, phrase_timeout=args.wait_minutes * args.phrase_timeout) + # We don't test transcription in oneshot mode + if not (is_oneshot := args.oneshot is not None): + transcriber = AudioTranscriber(model=args.audio_model, phrase_timeout=args.wait_minutes * args.phrase_timeout) + + # Create each of our thread objects with the apppropriate command line args buffer = TextBuffer( wait_minutes=args.wait_minutes, max_context=args.max_context, persistence=args.persistence_of_memory ) @@ -127,7 +135,8 @@ def on_image_rendered(image: Image | None) -> None: session_data.save_image(image) # start each thread with the appropriate callback - Thread(target=transcriber.start, args=(on_text_transcribed,), daemon=True).start() + if not is_oneshot: + Thread(target=transcriber.start, args=(on_text_transcribed,), daemon=True).start() Thread(target=summarizer.start, args=(on_summary_generated,), daemon=True).start() Thread(target=renderer.start, args=(on_image_rendered,), daemon=True).start() @@ -145,6 +154,12 @@ def open_browser() -> None: Thread(target=lambda: open_browser).start() + if is_oneshot: + # Read all the lines from the file, pretend we transcribed them + for line in args.oneshot: # type: ignore + # This will still dump things in the data directory. No sense short circuiting the testing. + on_text_transcribed(Transcription(line.strip())) + # flask feels like it probably has a good ctrl+c handler, so we'll make this one the main thread server.start()