Skip to content

Commit

Permalink
example
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrean committed Nov 15, 2023
1 parent b13de7b commit 5fbcb00
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 88 deletions.
178 changes: 91 additions & 87 deletions lib/app_web/live/page_live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -18,111 +18,115 @@
>Bumblebee</a>.
</p>
<!-- File upload section -->
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
<div class="col-span-full">
<div
class="mt-2 flex justify-center rounded-lg border border-dashed border-gray-900/25 px-6 py-10"
phx-drop-target={@uploads.image_list.ref}
>
<div class="text-center">
<!-- Show image preview -->
<%= if @image_preview_base64 do %>
<form id="upload-form" phx-change="noop" phx-submit="noop">
<label class="cursor-pointer">
<.live_file_input upload={@uploads.image_list} class="hidden" />
<img src={@image_preview_base64} />
</label>
</form>
<% else %>
<div class="col-span-full">
<div
class="mt-2 flex justify-center rounded-lg border border-dashed border-gray-900/25 px-6 py-10"
phx-drop-target={@uploads.image_list.ref}
>
<div class="text-center">
<!-- Show image preview -->
<%= if @image_preview_base64 do %>
<form id="upload-form" phx-change="noop" phx-submit="noop">
<label class="cursor-pointer">
<.live_file_input upload={@uploads.image_list} class="hidden" />
<img src={@image_preview_base64} />
</label>
</form>
<% else %>
<svg
class="mx-auto h-12 w-12 text-gray-300"
viewBox="0 0 24 24"
fill="currentColor"
aria-hidden="true"
>
<path
fill-rule="evenodd"
d="M1.5 6a2.25 2.25 0 012.25-2.25h16.5A2.25 2.25 0 0122.5 6v12a2.25 2.25 0 01-2.25 2.25H3.75A2.25 2.25 0 011.5 18V6zM3 16.06V18c0 .414.336.75.75.75h16.5A.75.75 0 0021 18v-1.94l-2.69-2.689a1.5 1.5 0 00-2.12 0l-.88.879.97.97a.75.75 0 11-1.06 1.06l-5.16-5.159a1.5 1.5 0 00-2.12 0L3 16.061zm10.125-7.81a1.125 1.125 0 112.25 0 1.125 1.125 0 01-2.25 0z"
clip-rule="evenodd"
/>
</svg>
<div class="mt-4 flex text-sm leading-6 text-gray-600">
<label
for="file-upload"
class="relative cursor-pointer rounded-md bg-white font-semibold text-indigo-600 focus-within:outline-none focus-within:ring-2 focus-within:ring-indigo-600 focus-within:ring-offset-2 hover:text-indigo-500"
>
<form id="upload-form" phx-change="noop" phx-submit="noop">
<label class="cursor-pointer">
<.live_file_input upload={@uploads.image_list} class="hidden" /> Upload
</label>
</form>
</label>
<p class="pl-1">or drag and drop</p>
</div>
<p class="text-xs leading-5 text-gray-600">PNG, JPG, GIF up to 5MB</p>
<% end %>
</div>
</div>
</div>
</div>
<!-- Show errors -->
<%= for entry <- @uploads.image_list.entries do %>
<div class="mt-2">
<%= for err <- upload_errors(@uploads.image_list, entry) do %>
<div class="rounded-md bg-red-50 p-4 mb-2">
<div class="flex">
<div class="flex-shrink-0">
<svg
class="mx-auto h-12 w-12 text-gray-300"
viewBox="0 0 24 24"
class="h-5 w-5 text-red-400"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
>
<path
fill-rule="evenodd"
d="M1.5 6a2.25 2.25 0 012.25-2.25h16.5A2.25 2.25 0 0122.5 6v12a2.25 2.25 0 01-2.25 2.25H3.75A2.25 2.25 0 011.5 18V6zM3 16.06V18c0 .414.336.75.75.75h16.5A.75.75 0 0021 18v-1.94l-2.69-2.689a1.5 1.5 0 00-2.12 0l-.88.879.97.97a.75.75 0 11-1.06 1.06l-5.16-5.159a1.5 1.5 0 00-2.12 0L3 16.061zm10.125-7.81a1.125 1.125 0 112.25 0 1.125 1.125 0 01-2.25 0z"
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z"
clip-rule="evenodd"
/>
</svg>
<div class="mt-4 flex text-sm leading-6 text-gray-600">
<label
for="file-upload"
class="relative cursor-pointer rounded-md bg-white font-semibold text-indigo-600 focus-within:outline-none focus-within:ring-2 focus-within:ring-indigo-600 focus-within:ring-offset-2 hover:text-indigo-500"
>
<form id="upload-form" phx-change="noop" phx-submit="noop">
<label class="cursor-pointer">
<.live_file_input upload={@uploads.image_list} class="hidden" /> Upload
</label>
</form>
</label>
<p class="pl-1">or drag and drop</p>
</div>
<p class="text-xs leading-5 text-gray-600">PNG, JPG, GIF up to 5MB</p>
<% end %>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">
<%= error_to_string(err) %>
</h3>
</div>
</div>
</div>
</div>
<% end %>
</div>
<!-- Show errors -->
<%= for entry <- @uploads.image_list.entries do %>
<div class="mt-2">
<%= for err <- upload_errors(@uploads.image_list, entry) do %>
<div class="rounded-md bg-red-50 p-4 mb-2">
<div class="flex">
<div class="flex-shrink-0">
<svg
class="h-5 w-5 text-red-400"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
>
<path
fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z"
clip-rule="evenodd"
/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">
<%= error_to_string(err) %>
</h3>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
<!-- Prediction text -->
<div class="mt-6 flex space-x-1.5 items-center font-bold text-gray-900 text-xl">
<span>Description: </span>
<!-- Spinner -->
<%= if @running do %>
<div role="status">
<div class="relative w-6 h-6 animate-spin rounded-full bg-gradient-to-r from-purple-400 via-blue-500 to-red-400 ">
<div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-3 h-3 bg-gray-200 rounded-full border-2 border-white">
</div>
<% end %>
<!-- Prediction text -->
<div class="mt-6 flex space-x-1.5 items-center font-bold text-gray-900 text-xl">
<span>Description: </span>
<!-- Spinner -->
<%= if @running do %>
<div role="status">
<div class="relative w-6 h-6 animate-spin rounded-full bg-gradient-to-r from-purple-400 via-blue-500 to-red-400 ">
<div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-3 h-3 bg-gray-200 rounded-full border-2 border-white">
</div>
</div>
</div>
<% else %>
<%= if @label do %>
<span class="text-gray-700 font-light"><%= @label %></span>
<% else %>
<%= if @label do %>
<span class="text-gray-700 font-light"><%= @label %></span>
<% else %>
<span class="text-gray-300 font-light">Waiting for image input.</span>
<% end %>
<span class="text-gray-300 font-light">Waiting for image input.</span>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
<div>
<%= if length(@displayed_list)>0 do %>
<figure :for={elt <- @displayed_list}>
<img src={elt.url} alt="surf" width="300" />
<figcaption><%= inspect(elt.label) %></figcaption>
</figure>
</div>
<%= if length(@displayed_list)>0 do %>
<div class="grid grid-cols-3 gap-4">
<%= for elt <- @displayed_list do %>
<div class="rounded overflow-hidden shadow-lg">
<img class="w-full h-20 object-cover" src={elt.url} alt="Image" />
<div class="px-6 py-4">
<div class="font-bold text-xl mb-2"><%= inspect(elt.label) %></div>
</div>
</div>
<% end %>
</div>
</div>
<% end %>

<div></div>
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ defmodule App.MixProject do
{:nx, "~> 0.6.4 "},

# Image
{:stb_image, "0.6.4"},
{:vix, "~> 0.24.0"},

# Testing
Expand Down

0 comments on commit 5fbcb00

Please sign in to comment.