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";
|
2023-05-18 23:55:46 +08:00
|
|
|
import type { ThemeMode } from "js/app/src/components/types";
|
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-06-06 09:11:53 +08:00
|
|
|
import StatusTracker from "../StatusTracker/StatusTracker.svelte";
|
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]>;
|
2023-06-15 21:27:18 +08:00
|
|
|
export let latex_delimiters: Array<{
|
|
|
|
left: string;
|
|
|
|
right: string;
|
|
|
|
display: boolean;
|
|
|
|
}>;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let container: boolean = false;
|
|
|
|
export let scale: number = 1;
|
|
|
|
export let min_width: number | undefined = undefined;
|
2022-06-02 01:02:18 +08:00
|
|
|
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;
|
2023-05-18 23:55:46 +08:00
|
|
|
export let theme_mode: ThemeMode;
|
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;
|
2023-06-16 05:58:31 +08:00
|
|
|
export let height: number = 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}
|
|
|
|
{container}
|
|
|
|
{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"}
|
|
|
|
disable={container === false}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
<ChatBot
|
|
|
|
{selectable}
|
|
|
|
{theme_mode}
|
|
|
|
value={_value}
|
|
|
|
{latex_delimiters}
|
|
|
|
pending_message={loading_status?.status === "pending"}
|
|
|
|
on:change
|
|
|
|
on:select
|
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>
|