agents-js-llama / src /lib /components /DataDisplay.svelte
nsarrazin's picture
nsarrazin HF Staff
latest updates
785ee56
raw
history blame contribute delete
898 Bytes
<script lang="ts">
import type { Data } from "../../app";
export let data: Data | Array<Data>;
const isBlob = (message: string | Blob): message is Blob => {
return message instanceof Blob;
};
</script>
<!-- if its an array recursively render for each children of the array -->
{#if Array.isArray(data)}
{#each data as el}
<svelte:self data={el} />
<div class="divider" />
{/each}
{:else if !!data && isBlob(data)}
{#if data.type.startsWith("image")}
<div class="mx-auto border-2 border-neutral-focus w-full">
<img class="p-1 w-fit" alt="generated" src={URL.createObjectURL(data)} />
</div>
{:else if data.type.startsWith("audio")}
<audio controls src={URL.createObjectURL(data)} />
{:else}
<p class="text-mono text-light w-full">blob type unknown</p>
{/if}
{:else if !!data}
<p class="text-mono mx-auto text-light w-full">{data}</p>
{/if}