2022-03-08 21:35:42 +08:00
|
|
|
<script lang="ts">
|
|
|
|
import { ChatBot } from "@gradio/chatbot";
|
2022-06-02 01:02:18 +08:00
|
|
|
import { Block, BlockLabel } from "@gradio/atoms";
|
2022-05-06 03:05:05 +08:00
|
|
|
import type { LoadingStatus } from "../StatusTracker/types";
|
2022-06-02 01:02:18 +08:00
|
|
|
import type { Styles } from "@gradio/utils";
|
|
|
|
import { Chat } from "@gradio/icons";
|
2023-03-13 22:21:03 +08:00
|
|
|
import type { FileData } from "@gradio/upload";
|
|
|
|
import { normalise_file } from "@gradio/upload";
|
2022-03-29 21:10:35 +08:00
|
|
|
|
2022-05-12 12:40:41 +08:00
|
|
|
export let elem_id: string = "";
|
2023-03-16 05:01:53 +08:00
|
|
|
export let elem_classes: Array<string> = [];
|
2022-06-17 07:49:54 +08:00
|
|
|
export let visible: boolean = true;
|
2023-03-13 22:21:03 +08:00
|
|
|
export let value: Array<
|
|
|
|
[string | FileData | null, string | FileData | null]
|
|
|
|
> = [];
|
|
|
|
let _value: Array<[string | FileData | null, string | FileData | null]>;
|
2022-06-02 01:02:18 +08:00
|
|
|
export let style: Styles = {};
|
|
|
|
export let label: string;
|
|
|
|
export let show_label: boolean = true;
|
2023-03-04 10:17:48 +08:00
|
|
|
export let root: string;
|
2023-03-13 22:21:03 +08:00
|
|
|
export let root_url: null | string;
|
2023-03-14 08:12:41 +08:00
|
|
|
export let selectable: boolean = false;
|
2022-06-02 01:02:18 +08:00
|
|
|
|
2023-03-13 22:21:03 +08:00
|
|
|
const redirect_src_url = (src: string) =>
|
|
|
|
src.replace('src="/file', `src="${root}file`);
|
2022-03-29 21:10:35 +08:00
|
|
|
|
2023-03-13 22:21:03 +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>
|
|
|
|
|
2023-03-16 05:01:53 +08:00
|
|
|
<Block {elem_id} {elem_classes} {visible} padding={false}>
|
2022-06-02 01:02:18 +08:00
|
|
|
{#if show_label}
|
|
|
|
<BlockLabel
|
|
|
|
{show_label}
|
|
|
|
Icon={Chat}
|
2023-03-07 04:52:31 +08:00
|
|
|
float={false}
|
2022-06-02 01:02:18 +08:00
|
|
|
label={label || "Chatbot"}
|
|
|
|
disable={typeof style.container === "boolean" && !style.container}
|
|
|
|
/>
|
|
|
|
{/if}
|
2023-01-31 09:09:14 +08:00
|
|
|
<ChatBot
|
2023-03-07 02:12:39 +08:00
|
|
|
{style}
|
2023-03-14 08:12:41 +08:00
|
|
|
{selectable}
|
2023-03-13 22:21:03 +08:00
|
|
|
value={_value}
|
2023-01-31 09:09:14 +08:00
|
|
|
pending_message={loading_status?.status === "pending"}
|
|
|
|
on:change
|
2023-03-14 08:12:41 +08:00
|
|
|
on:select
|
2023-01-31 09:09:14 +08:00
|
|
|
/>
|
2022-04-26 22:48:39 +08:00
|
|
|
</Block>
|