diff --git a/lib/imaginative_restoration/ai/utils.ex b/lib/imaginative_restoration/ai/utils.ex index e1b0bfc..ab97dbf 100644 --- a/lib/imaginative_restoration/ai/utils.ex +++ b/lib/imaginative_restoration/ai/utils.ex @@ -74,8 +74,6 @@ defmodule ImaginativeRestoration.AI.Utils do mean = Enum.sum(diffs) / length(diffs) - dbg({diffs, mean}) - # the docs say "In general, a hamming distance of less than 10 indicates that the images are very similar." mean >= 10 end diff --git a/lib/imaginative_restoration_web/live/index_live.ex b/lib/imaginative_restoration_web/live/index_live.ex index 9b50580..45a3ab3 100644 --- a/lib/imaginative_restoration_web/live/index_live.ex +++ b/lib/imaginative_restoration_web/live/index_live.ex @@ -43,21 +43,20 @@ defmodule ImaginativeRestorationWeb.IndexLive do def handle_event("webcam_frame", %{"frame" => dataurl}, socket) do pid = self() - if not Utils.changed_recently?(5) do - Logger.info("Skipping frame processing") + # only run the AI pipeline if stuff has changed recently + if Utils.changed_recently?(5) do + # spawn the task which will communicate back to self() via :update_sketch messages + Task.start(fn -> + dataurl + |> ImaginativeRestoration.Sketches.init!() + |> send_update_sketch_message(pid) + |> ImaginativeRestoration.Sketches.crop_and_set_prompt!() + |> send_update_sketch_message(pid) + |> ImaginativeRestoration.Sketches.process!() + |> send_update_sketch_message(pid) + end) end - # spawn the task which will communicate back to self() via :update_sketch messages - Task.start(fn -> - dataurl - |> ImaginativeRestoration.Sketches.init!() - |> send_update_sketch_message(pid) - |> ImaginativeRestoration.Sketches.crop_and_set_prompt!() - |> send_update_sketch_message(pid) - |> ImaginativeRestoration.Sketches.process!() - |> send_update_sketch_message(pid) - end) - {:noreply, socket} end