gradio/js/app/src/components/Chatbot/Chatbot.svelte

59 lines
1.7 KiB
Svelte
Raw Normal View History

2022-03-08 21:35:42 +08:00
<script lang="ts">
import { ChatBot } from "@gradio/chatbot";
import { Block, BlockLabel } from "@gradio/atoms";
import type { LoadingStatus } from "../StatusTracker/types";
import type { Styles } from "@gradio/utils";
import { Chat } from "@gradio/icons";
import type { FileData } from "@gradio/upload";
import { normalise_file } from "@gradio/upload";
2022-03-29 21:10:35 +08:00
export let elem_id: string = "";
export let elem_classes: Array<string> = [];
export let visible: boolean = true;
export let value: Array<
[string | FileData | null, string | FileData | null]
> = [];
let _value: Array<[string | FileData | null, string | FileData | null]>;
export let style: Styles = {};
export let label: string;
export let show_label: boolean = true;
export let root: string;
export let root_url: null | string;
export let selectable: boolean = false;
const redirect_src_url = (src: string) =>
src.replace('src="/file', `src="${root}file`);
2022-03-29 21:10:35 +08:00
$: _value = value
? value.map(([user_msg, bot_msg]) => [
typeof user_msg === "string"
? redirect_src_url(user_msg)
: normalise_file(user_msg, root, root_url),
typeof bot_msg === "string"
? redirect_src_url(bot_msg)
: normalise_file(bot_msg, root, root_url)
])
: [];
export let loading_status: LoadingStatus | undefined = undefined;
2022-03-08 21:35:42 +08:00
</script>
<Block {elem_id} {elem_classes} {visible} padding={false}>
{#if show_label}
<BlockLabel
{show_label}
Icon={Chat}
Python backend to theming (#2931) * add theme + theme atoms * audio * buttons * chatbot * forms * start file * complete file * fixup workbench * gallery * highlighted text * label * json * upload * 3d model * atoms * chart * md + html * image * plot + build * table * tabs * tooltip * upload * tweaks * tweaks + more tooling * tweaks to padding/ lineheight * app components _ start api docs * format, more api docs * finish api docs * interpretation * todos * tweaks + cleanup * tweaks + cleanup * revert range tweaks * fix notebooks * fix test * remove tw * cleanup + login * fix gitignore * fix types * run css script * fix progress + tweaks * update demos * add css build to static check workflow * tweak ci * fix tests * tweak markdown * tweak chatbot + file * fix tabs * tweak tabs * cleanup * fix api docs * fix example gallery * add gradient to toast * fix min height for interfaces * revert tab changes * update notebooks * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * fix * changes * changes * changes * changes * changes * changes * undo radius * undo radius * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * change * undo * Add absolute imports * mock theme in tests * clean * changes * changes --------- Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-03-07 04:52:31 +08:00
float={false}
label={label || "Chatbot"}
disable={typeof style.container === "boolean" && !style.container}
/>
{/if}
<ChatBot
{style}
{selectable}
value={_value}
pending_message={loading_status?.status === "pending"}
on:change
on:select
/>
</Block>