Download ui/web/src/components/chat/VisionControls.svelte from localailb/assistant: direct link, hf CLI and curl.
- Browser
- Download file 4.34 kB
-
https://huggingface.co/spaces/localailb/assistant/resolve/main/ui/web/src/components/chat/VisionControls.svelte
- Command line
-
hf download hf://spaces/localailb/assistant/ui/web/src/components/chat/VisionControls.svelte
-
curl -L -o VisionControls.svelte https://huggingface.co/spaces/localailb/assistant/resolve/main/ui/web/src/components/chat/VisionControls.svelte
4.34 kB
| <script> | |
| import { t } from "../../lib/stores.svelte.js"; | |
| import { fetchMmproj, uploadImage } from "../../lib/api.js"; | |
| import "./Controls.css"; | |
| import MiniSelect from "./MiniSelect.svelte"; | |
| /** modelLabel/providerLabel come from the header pickers (read-only); the | |
| * image/rag bindables feed the pane's send payload and clear/save flows, | |
| * and mmprojLabel carries the selected projector back to ChatPane. The | |
| * mmproj choices + visibility are internal (only rendered here). | |
| * notify(msg, isErr) surfaces upload errors via the shared flash line. | |
| * | |
| * The component is split into two movable halves so the layout can keep | |
| * the image upload visible next to the composer while tucking the | |
| * projector select into the collapsed "Generation Settings" section: | |
| * - imageOnly — render ONLY the upload chip + preview (the vision | |
| * INPUT, not a setting). Skips the mmproj fetch. | |
| * - projectorOnly — render ONLY the mmproj select (the projector | |
| * choice is a setting). This instance owns the | |
| * /api/mmproj fetch. | |
| * Default (neither) keeps the legacy combined layout. */ | |
| let { | |
| modelLabel, | |
| providerLabel, | |
| imagePath = $bindable(), | |
| imagePreview = $bindable(), | |
| mmprojLabel = $bindable(), | |
| notify, | |
| imageOnly = false, | |
| projectorOnly = false, | |
| } = $props(); | |
| let mmprojChoices = $state([]); | |
| let mmprojVisible = $state(false); | |
| // Guards stale /api/mmproj responses (the header pickers re-run the effect). | |
| let mmprojFetched = 0; | |
| async function onPickImage(e) { | |
| const file = e.currentTarget.files?.[0]; | |
| e.currentTarget.value = ""; // allow re-picking the same file | |
| if (!file) return; | |
| if (!file.type.startsWith("image/")) { | |
| notify(t("web_upload_fail"), true); | |
| return; | |
| } | |
| if (file.size > 25 * 1024 * 1024) { | |
| notify(t("web_upload_fail"), true); | |
| return; | |
| } | |
| try { | |
| const r = await uploadImage(file); | |
| imagePath = r.path; | |
| if (imagePreview) URL.revokeObjectURL(imagePreview); | |
| imagePreview = URL.createObjectURL(file); | |
| notify("", false); | |
| } catch { | |
| notify(t("web_upload_fail"), true); | |
| } | |
| } | |
| function removeImage() { | |
| if (imagePreview) URL.revokeObjectURL(imagePreview); | |
| imagePreview = ""; | |
| imagePath = ""; | |
| } | |
| // Refresh mmproj choices whenever the header pickers change (the Gradio | |
| // vlm_dd.change parity — GGUF VLMs under llama.cpp providers only). Only | |
| // the projector-rendering instance fetches — an imageOnly duplicate would | |
| // fire a second request for the same data. | |
| $effect(() => { | |
| if (imageOnly) return; | |
| void modelLabel; | |
| void providerLabel; | |
| const req = ++mmprojFetched; | |
| mmprojVisible = false; | |
| mmprojChoices = []; | |
| if (!modelLabel || !providerLabel) return; | |
| fetchMmproj(modelLabel, providerLabel) | |
| .then((r) => { | |
| if (req !== mmprojFetched) return; // stale response | |
| mmprojVisible = !!r.visible; | |
| mmprojChoices = r.choices ?? []; | |
| mmprojLabel = r.saved ?? ""; | |
| }) | |
| .catch(() => { | |
| if (req !== mmprojFetched) return; | |
| mmprojVisible = false; | |
| mmprojChoices = []; | |
| }); | |
| }); | |
| </script> | |
| {#if !projectorOnly} | |
| <div class="image-row"> | |
| <label class="chip upload-chip" data-tooltip={t("web_tt_upload_image")}> | |
| <input | |
| type="file" | |
| accept="image/*" | |
| onchange={onPickImage} | |
| hidden | |
| /> | |
| {t("web_upload_image")} | |
| </label> | |
| {#if imagePreview} | |
| <div class="img-preview"> | |
| <img src={imagePreview} alt="" /> | |
| <button | |
| class="img-remove" | |
| onclick={removeImage} | |
| data-tooltip={t("web_tt_remove_image")} | |
| aria-label={t("web_tt_remove_image")} | |
| >×</button> | |
| </div> | |
| {/if} | |
| </div> | |
| {/if} | |
| {#if !imageOnly && mmprojVisible} | |
| <div class="theme-row"> | |
| <label class="mini-field" data-tooltip={t("web_tt_mmproj")}> | |
| <span>{t("web_mmproj")}</span> | |
| <MiniSelect | |
| bind:value={mmprojLabel} | |
| options={mmprojChoices} | |
| emptyLabel="Auto" | |
| tip={t("web_tt_mmproj")} | |
| /> | |
| </label> | |
| </div> | |
| {/if} | |