2022-03-08 21:35:42 +08:00
|
|
|
<script lang="ts">
|
2023-09-02 07:20:55 +08:00
|
|
|
import type { Gradio, SelectData, LikeData } from "@gradio/utils";
|
2023-08-24 04:48:10 +08:00
|
|
|
|
2023-08-04 06:01:18 +08:00
|
|
|
import ChatBot from "./ChatBot.svelte";
|
2022-06-02 01:02:18 +08:00
|
|
|
import { Block, BlockLabel } from "@gradio/atoms";
|
2023-08-04 06:01:18 +08:00
|
|
|
import type { LoadingStatus } from "@gradio/statustracker";
|
2022-06-02 01:02:18 +08:00
|
|
|
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";
|
2023-08-04 06:01:18 +08:00
|
|
|
import { StatusTracker } from "@gradio/statustracker";
|
2022-03-29 21:10:35 +08:00
|
|
|
|
2023-07-14 00:41:47 +08:00
|
|
|
export let elem_id = "";
|
|
|
|
export let elem_classes: string[] = [];
|
|
|
|
export let visible = true;
|
|
|
|
export let value: [string | FileData | null, string | FileData | null][] = [];
|
2023-06-22 03:34:12 +08:00
|
|
|
export let scale: number | null = null;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let min_width: number | undefined = undefined;
|
2022-06-02 01:02:18 +08:00
|
|
|
export let label: string;
|
2023-07-14 00:41:47 +08:00
|
|
|
export let show_label = 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-07-14 00:41:47 +08:00
|
|
|
export let selectable = false;
|
2023-09-02 07:20:55 +08:00
|
|
|
export let likeable = false;
|
2023-07-14 00:41:47 +08:00
|
|
|
export let show_share_button = false;
|
2023-07-18 00:53:23 +08:00
|
|
|
export let rtl = false;
|
2023-08-10 22:11:26 +08:00
|
|
|
export let show_copy_button = false;
|
2023-08-29 12:26:29 +08:00
|
|
|
export let sanitize_html = true;
|
2023-08-29 08:48:52 +08:00
|
|
|
export let bubble_full_width = true;
|
2023-10-03 01:29:20 +08:00
|
|
|
export let layout: "bubble" | "panel" = "bubble";
|
2023-09-23 02:53:09 +08:00
|
|
|
export let render_markdown = true;
|
2023-08-04 06:01:18 +08:00
|
|
|
export let latex_delimiters: {
|
|
|
|
left: string;
|
|
|
|
right: string;
|
|
|
|
display: boolean;
|
|
|
|
}[];
|
2023-08-24 04:48:10 +08:00
|
|
|
export let gradio: Gradio<{
|
|
|
|
change: typeof value;
|
|
|
|
select: SelectData;
|
|
|
|
share: ShareData;
|
|
|
|
error: string;
|
2023-09-02 07:20:55 +08:00
|
|
|
like: LikeData;
|
2023-08-24 04:48:10 +08:00
|
|
|
}>;
|
2023-08-23 06:05:22 +08:00
|
|
|
export let avatar_images: [string | null, string | null] = [null, null];
|
2023-08-04 06:01:18 +08:00
|
|
|
|
|
|
|
let _value: [string | FileData | null, string | FileData | null][];
|
2022-06-02 01:02:18 +08:00
|
|
|
|
2023-07-14 00:41:47 +08:00
|
|
|
const redirect_src_url = (src: string): string =>
|
2023-03-13 22:21:03 +08:00
|
|
|
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)
|
2023-10-03 01:29:20 +08:00
|
|
|
: normalise_file(bot_msg, root, root_url),
|
2023-03-13 22:21:03 +08:00
|
|
|
])
|
|
|
|
: [];
|
2023-08-22 05:15:59 +08:00
|
|
|
|
2023-03-13 22:21:03 +08:00
|
|
|
export let loading_status: LoadingStatus | undefined = undefined;
|
2023-07-14 00:41:47 +08:00
|
|
|
export let height = 400;
|
2022-03-08 21:35:42 +08:00
|
|
|
</script>
|
|
|
|
|
2023-06-08 09:35:31 +08:00
|
|
|
<Block
|
|
|
|
{elem_id}
|
|
|
|
{elem_classes}
|
|
|
|
{visible}
|
|
|
|
padding={false}
|
|
|
|
{scale}
|
|
|
|
{min_width}
|
|
|
|
{height}
|
|
|
|
allow_overflow={false}
|
|
|
|
>
|
2023-06-06 09:11:53 +08:00
|
|
|
{#if loading_status}
|
|
|
|
<StatusTracker
|
|
|
|
{...loading_status}
|
|
|
|
show_progress={loading_status.show_progress === "hidden"
|
|
|
|
? "hidden"
|
|
|
|
: "minimal"}
|
|
|
|
/>
|
|
|
|
{/if}
|
2023-06-16 05:58:31 +08:00
|
|
|
<div class="wrapper">
|
|
|
|
{#if show_label}
|
|
|
|
<BlockLabel
|
|
|
|
{show_label}
|
|
|
|
Icon={Chat}
|
|
|
|
float={false}
|
|
|
|
label={label || "Chatbot"}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
<ChatBot
|
|
|
|
{selectable}
|
2023-09-02 07:20:55 +08:00
|
|
|
{likeable}
|
2023-07-06 08:50:17 +08:00
|
|
|
{show_share_button}
|
2023-06-16 05:58:31 +08:00
|
|
|
value={_value}
|
|
|
|
{latex_delimiters}
|
2023-09-23 02:53:09 +08:00
|
|
|
{render_markdown}
|
2023-06-16 05:58:31 +08:00
|
|
|
pending_message={loading_status?.status === "pending"}
|
2023-07-18 00:53:23 +08:00
|
|
|
{rtl}
|
2023-08-10 22:11:26 +08:00
|
|
|
{show_copy_button}
|
2023-08-24 04:48:10 +08:00
|
|
|
on:change={() => gradio.dispatch("change", value)}
|
|
|
|
on:select={(e) => gradio.dispatch("select", e.detail)}
|
2023-09-02 07:20:55 +08:00
|
|
|
on:like={(e) => gradio.dispatch("like", e.detail)}
|
2023-08-24 04:48:10 +08:00
|
|
|
on:share={(e) => gradio.dispatch("share", e.detail)}
|
|
|
|
on:error={(e) => gradio.dispatch("error", e.detail)}
|
2023-08-22 05:15:59 +08:00
|
|
|
{avatar_images}
|
2023-08-29 12:26:29 +08:00
|
|
|
{sanitize_html}
|
2023-08-29 08:48:52 +08:00
|
|
|
{bubble_full_width}
|
2023-10-03 01:29:20 +08:00
|
|
|
{layout}
|
2023-08-22 05:15:59 +08:00
|
|
|
{root_url}
|
|
|
|
{root}
|
2022-06-02 01:02:18 +08:00
|
|
|
/>
|
2023-06-16 05:58:31 +08:00
|
|
|
</div>
|
2022-04-26 22:48:39 +08:00
|
|
|
</Block>
|
2023-06-16 05:58:31 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.wrapper {
|
|
|
|
display: flex;
|
|
|
|
position: relative;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: start;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
</style>
|