Upload folder using huggingface_hub
Browse files
6.0.0-dev.4/chatbot/shared/ButtonPanel.svelte
CHANGED
|
@@ -2,11 +2,17 @@
|
|
| 2 |
import LikeDislike from "./LikeDislike.svelte";
|
| 3 |
import Copy from "./Copy.svelte";
|
| 4 |
import type { FileData } from "@gradio/client";
|
| 5 |
-
import type { NormalisedMessage
|
| 6 |
-
import { Retry, Undo, Edit, Check, Clear } from "@gradio/icons";
|
| 7 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import { all_text, is_all_text } from "./utils";
|
| 9 |
import type { I18nFormatter } from "js/core/src/gradio_helper";
|
|
|
|
| 10 |
|
| 11 |
export let i18n: I18nFormatter;
|
| 12 |
export let likeable: boolean;
|
|
@@ -22,6 +28,9 @@
|
|
| 22 |
export let avatar: FileData | null;
|
| 23 |
export let generating: boolean;
|
| 24 |
export let current_feedback: string | null;
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
export let handle_action: (selected: string | null) => void;
|
| 27 |
export let layout: "bubble" | "panel";
|
|
@@ -31,7 +40,7 @@
|
|
| 31 |
$: show_copy = show_copy_button && message && is_all_text(message);
|
| 32 |
</script>
|
| 33 |
|
| 34 |
-
{#if show_copy || show_retry || show_undo || show_edit || likeable}
|
| 35 |
<div
|
| 36 |
class="message-buttons-{position} {layout} message-buttons {avatar !==
|
| 37 |
null && 'with-avatar'}"
|
|
@@ -59,6 +68,37 @@
|
|
| 59 |
{i18n}
|
| 60 |
/>
|
| 61 |
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
{#if show_retry}
|
| 63 |
<IconButton
|
| 64 |
Icon={Retry}
|
|
|
|
| 2 |
import LikeDislike from "./LikeDislike.svelte";
|
| 3 |
import Copy from "./Copy.svelte";
|
| 4 |
import type { FileData } from "@gradio/client";
|
| 5 |
+
import type { NormalisedMessage } from "../types";
|
| 6 |
+
import { Retry, Undo, Edit, Check, Clear, Download } from "@gradio/icons";
|
| 7 |
+
import {
|
| 8 |
+
IconButtonWrapper,
|
| 9 |
+
IconButton,
|
| 10 |
+
DownloadLink,
|
| 11 |
+
ShareButton
|
| 12 |
+
} from "@gradio/atoms";
|
| 13 |
import { all_text, is_all_text } from "./utils";
|
| 14 |
import type { I18nFormatter } from "js/core/src/gradio_helper";
|
| 15 |
+
import { uploadToHuggingFace } from "@gradio/utils";
|
| 16 |
|
| 17 |
export let i18n: I18nFormatter;
|
| 18 |
export let likeable: boolean;
|
|
|
|
| 28 |
export let avatar: FileData | null;
|
| 29 |
export let generating: boolean;
|
| 30 |
export let current_feedback: string | null;
|
| 31 |
+
export let file: FileData | null = null;
|
| 32 |
+
export let show_download_button = false;
|
| 33 |
+
export let show_share_button = false;
|
| 34 |
|
| 35 |
export let handle_action: (selected: string | null) => void;
|
| 36 |
export let layout: "bubble" | "panel";
|
|
|
|
| 40 |
$: show_copy = show_copy_button && message && is_all_text(message);
|
| 41 |
</script>
|
| 42 |
|
| 43 |
+
{#if show_copy || show_retry || show_undo || show_edit || likeable || show_download_button || show_share_button}
|
| 44 |
<div
|
| 45 |
class="message-buttons-{position} {layout} message-buttons {avatar !==
|
| 46 |
null && 'with-avatar'}"
|
|
|
|
| 68 |
{i18n}
|
| 69 |
/>
|
| 70 |
{/if}
|
| 71 |
+
{#if show_download_button && file?.url}
|
| 72 |
+
<DownloadLink
|
| 73 |
+
href={file.is_stream
|
| 74 |
+
? file.url?.replace("playlist.m3u8", "playlist-file")
|
| 75 |
+
: file.url}
|
| 76 |
+
download={file.orig_name || file.path || "file"}
|
| 77 |
+
>
|
| 78 |
+
<IconButton Icon={Download} label={i18n("common.download")} />
|
| 79 |
+
</DownloadLink>
|
| 80 |
+
{/if}
|
| 81 |
+
{#if show_share_button && file}
|
| 82 |
+
<ShareButton
|
| 83 |
+
{i18n}
|
| 84 |
+
on:error={(e) => dispatch("error", e.detail)}
|
| 85 |
+
on:share={(e) => dispatch("share", e.detail)}
|
| 86 |
+
formatter={async (value) => {
|
| 87 |
+
if (!value) return "";
|
| 88 |
+
let url = await uploadToHuggingFace(value.url, "url");
|
| 89 |
+
const mime_type = value.mime_type || "";
|
| 90 |
+
if (mime_type.startsWith("audio/")) {
|
| 91 |
+
return `<audio controls src="${url}"></audio>`;
|
| 92 |
+
} else if (mime_type.startsWith("video/")) {
|
| 93 |
+
return `<video controls src="${url}"></video>`;
|
| 94 |
+
} else if (mime_type.startsWith("image/")) {
|
| 95 |
+
return `<img src="${url}" />`;
|
| 96 |
+
}
|
| 97 |
+
return "";
|
| 98 |
+
}}
|
| 99 |
+
value={file}
|
| 100 |
+
/>
|
| 101 |
+
{/if}
|
| 102 |
{#if show_retry}
|
| 103 |
<IconButton
|
| 104 |
Icon={Retry}
|
6.0.0-dev.4/chatbot/shared/Component.svelte
CHANGED
|
@@ -19,7 +19,17 @@
|
|
| 19 |
export let allow_file_downloads: boolean;
|
| 20 |
export let display_icon_button_wrapper_top_corner = false;
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
</script>
|
| 24 |
|
| 25 |
{#if type === "gallery"}
|
|
@@ -27,7 +37,7 @@
|
|
| 27 |
this={components[type]}
|
| 28 |
{...props}
|
| 29 |
{value}
|
| 30 |
-
{
|
| 31 |
show_label={props.label ? true : false}
|
| 32 |
{i18n}
|
| 33 |
{_fetch}
|
|
@@ -68,23 +78,22 @@
|
|
| 68 |
on:load
|
| 69 |
/>
|
| 70 |
{:else if type === "audio"}
|
| 71 |
-
<
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
waveform_settings
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
</div>
|
| 88 |
{:else if type === "video"}
|
| 89 |
<svelte:component
|
| 90 |
this={components[type]}
|
|
@@ -92,33 +101,38 @@
|
|
| 92 |
autoplay={props.autoplay}
|
| 93 |
value={value.video || value}
|
| 94 |
show_label={props.label ? true : false}
|
| 95 |
-
show_share_button={
|
| 96 |
{i18n}
|
| 97 |
{upload}
|
| 98 |
-
{
|
| 99 |
-
show_download_button={
|
| 100 |
on:load
|
| 101 |
>
|
| 102 |
<track kind="captions" />
|
| 103 |
</svelte:component>
|
| 104 |
{:else if type === "image"}
|
| 105 |
-
<
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
{:else if type === "html"}
|
| 116 |
<svelte:component
|
| 117 |
this={components[type]}
|
| 118 |
{...props}
|
| 119 |
{value}
|
| 120 |
show_label={false}
|
| 121 |
-
show_share_button={
|
| 122 |
{i18n}
|
| 123 |
gradio={{ dispatch: () => {} }}
|
| 124 |
on:load
|
|
@@ -139,7 +153,7 @@
|
|
| 139 |
show_label={props.label ? true : false}
|
| 140 |
root=""
|
| 141 |
interactive={false}
|
| 142 |
-
show_share_button={
|
| 143 |
gradio={{ dispatch: () => {}, i18n }}
|
| 144 |
on:load
|
| 145 |
{i18n}
|
|
|
|
| 19 |
export let allow_file_downloads: boolean;
|
| 20 |
export let display_icon_button_wrapper_top_corner = false;
|
| 21 |
|
| 22 |
+
let image_fullscreen = false;
|
| 23 |
+
let image_container: HTMLElement;
|
| 24 |
+
|
| 25 |
+
function handle_fullscreen(event: CustomEvent<boolean>): void {
|
| 26 |
+
image_fullscreen = event.detail;
|
| 27 |
+
if (image_fullscreen && image_container) {
|
| 28 |
+
image_container.requestFullscreen?.();
|
| 29 |
+
} else if (document.fullscreenElement) {
|
| 30 |
+
document.exitFullscreen?.();
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
</script>
|
| 34 |
|
| 35 |
{#if type === "gallery"}
|
|
|
|
| 37 |
this={components[type]}
|
| 38 |
{...props}
|
| 39 |
{value}
|
| 40 |
+
display_icon_button_wrapper_top_corner={false}
|
| 41 |
show_label={props.label ? true : false}
|
| 42 |
{i18n}
|
| 43 |
{_fetch}
|
|
|
|
| 78 |
on:load
|
| 79 |
/>
|
| 80 |
{:else if type === "audio"}
|
| 81 |
+
<svelte:component
|
| 82 |
+
this={components[type]}
|
| 83 |
+
{...props}
|
| 84 |
+
{value}
|
| 85 |
+
show_label={props.label ? true : false}
|
| 86 |
+
show_share_button={false}
|
| 87 |
+
{i18n}
|
| 88 |
+
waveform_settings={{
|
| 89 |
+
...props.waveform_settings,
|
| 90 |
+
autoplay: props.autoplay
|
| 91 |
+
}}
|
| 92 |
+
show_download_button={false}
|
| 93 |
+
display_icon_button_wrapper_top_corner={false}
|
| 94 |
+
minimal={true}
|
| 95 |
+
on:load
|
| 96 |
+
/>
|
|
|
|
| 97 |
{:else if type === "video"}
|
| 98 |
<svelte:component
|
| 99 |
this={components[type]}
|
|
|
|
| 101 |
autoplay={props.autoplay}
|
| 102 |
value={value.video || value}
|
| 103 |
show_label={props.label ? true : false}
|
| 104 |
+
show_share_button={false}
|
| 105 |
{i18n}
|
| 106 |
{upload}
|
| 107 |
+
display_icon_button_wrapper_top_corner={false}
|
| 108 |
+
show_download_button={false}
|
| 109 |
on:load
|
| 110 |
>
|
| 111 |
<track kind="captions" />
|
| 112 |
</svelte:component>
|
| 113 |
{:else if type === "image"}
|
| 114 |
+
<div bind:this={image_container}>
|
| 115 |
+
<svelte:component
|
| 116 |
+
this={components[type]}
|
| 117 |
+
{...props}
|
| 118 |
+
{value}
|
| 119 |
+
show_label={props.label ? true : false}
|
| 120 |
+
display_icon_button_wrapper_top_corner={false}
|
| 121 |
+
buttons={["fullscreen"]}
|
| 122 |
+
fullscreen={image_fullscreen}
|
| 123 |
+
show_button_background={false}
|
| 124 |
+
on:fullscreen={handle_fullscreen}
|
| 125 |
+
on:load
|
| 126 |
+
{i18n}
|
| 127 |
+
/>
|
| 128 |
+
</div>
|
| 129 |
{:else if type === "html"}
|
| 130 |
<svelte:component
|
| 131 |
this={components[type]}
|
| 132 |
{...props}
|
| 133 |
{value}
|
| 134 |
show_label={false}
|
| 135 |
+
show_share_button={false}
|
| 136 |
{i18n}
|
| 137 |
gradio={{ dispatch: () => {} }}
|
| 138 |
on:load
|
|
|
|
| 153 |
show_label={props.label ? true : false}
|
| 154 |
root=""
|
| 155 |
interactive={false}
|
| 156 |
+
show_share_button={false}
|
| 157 |
gradio={{ dispatch: () => {}, i18n }}
|
| 158 |
on:load
|
| 159 |
{i18n}
|
6.0.0-dev.4/chatbot/shared/LikeDislike.svelte
CHANGED
|
@@ -26,9 +26,7 @@
|
|
| 26 |
{#if feedback_options.includes("Dislike")}
|
| 27 |
<IconButton
|
| 28 |
Icon={selected === "Dislike" ? ThumbDownActive : ThumbDownDefault}
|
| 29 |
-
label={selected === "Dislike"
|
| 30 |
-
? "clicked dislike"
|
| 31 |
-
: i18n("chatbot.dislike")}
|
| 32 |
color={selected === "Dislike"
|
| 33 |
? "var(--color-accent)"
|
| 34 |
: "var(--block-label-text-color)"}
|
|
@@ -38,7 +36,7 @@
|
|
| 38 |
{#if feedback_options.includes("Like")}
|
| 39 |
<IconButton
|
| 40 |
Icon={selected === "Like" ? ThumbUpActive : ThumbUpDefault}
|
| 41 |
-
label={selected === "Like" ? "
|
| 42 |
color={selected === "Like"
|
| 43 |
? "var(--color-accent)"
|
| 44 |
: "var(--block-label-text-color)"}
|
|
|
|
| 26 |
{#if feedback_options.includes("Dislike")}
|
| 27 |
<IconButton
|
| 28 |
Icon={selected === "Dislike" ? ThumbDownActive : ThumbDownDefault}
|
| 29 |
+
label={selected === "Dislike" ? "Disliked" : i18n("chatbot.dislike")}
|
|
|
|
|
|
|
| 30 |
color={selected === "Dislike"
|
| 31 |
? "var(--color-accent)"
|
| 32 |
: "var(--block-label-text-color)"}
|
|
|
|
| 36 |
{#if feedback_options.includes("Like")}
|
| 37 |
<IconButton
|
| 38 |
Icon={selected === "Like" ? ThumbUpActive : ThumbUpDefault}
|
| 39 |
+
label={selected === "Like" ? "Liked" : i18n("chatbot.like")}
|
| 40 |
color={selected === "Like"
|
| 41 |
? "var(--color-accent)"
|
| 42 |
: "var(--block-label-text-color)"}
|
6.0.0-dev.4/chatbot/shared/Message.svelte
CHANGED
|
@@ -90,6 +90,22 @@
|
|
| 90 |
return `a component of type ${message.content.component ?? "unknown"}`;
|
| 91 |
}
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
type ButtonPanelProps = {
|
| 94 |
handle_action: (selected: string | null) => void;
|
| 95 |
likeable: boolean;
|
|
@@ -107,6 +123,9 @@
|
|
| 107 |
dispatch: any;
|
| 108 |
current_feedback: string | null;
|
| 109 |
watermark: string | null;
|
|
|
|
|
|
|
|
|
|
| 110 |
};
|
| 111 |
|
| 112 |
let button_panel_props: ButtonPanelProps;
|
|
@@ -126,7 +145,10 @@
|
|
| 126 |
layout,
|
| 127 |
dispatch,
|
| 128 |
current_feedback,
|
| 129 |
-
watermark
|
|
|
|
|
|
|
|
|
|
| 130 |
};
|
| 131 |
</script>
|
| 132 |
|
|
@@ -256,13 +278,16 @@
|
|
| 256 |
.message {
|
| 257 |
position: relative;
|
| 258 |
width: 100%;
|
| 259 |
-
margin-top: var(--spacing-sm);
|
| 260 |
}
|
| 261 |
|
| 262 |
.message.display_consecutive_in_same_bubble {
|
| 263 |
margin-top: 0;
|
| 264 |
}
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
/* avatar styles */
|
| 267 |
.avatar-container {
|
| 268 |
flex-shrink: 0;
|
|
|
|
| 90 |
return `a component of type ${message.content.component ?? "unknown"}`;
|
| 91 |
}
|
| 92 |
|
| 93 |
+
function get_file(messages: NormalisedMessage[]): FileData | null {
|
| 94 |
+
for (const message of messages) {
|
| 95 |
+
if (
|
| 96 |
+
message.type === "component" &&
|
| 97 |
+
(message.content.component === "audio" ||
|
| 98 |
+
message.content.component === "video" ||
|
| 99 |
+
message.content.component === "image" ||
|
| 100 |
+
message.content.component === "file") &&
|
| 101 |
+
message.content.value
|
| 102 |
+
) {
|
| 103 |
+
return message.content.value as FileData;
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
return null;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
type ButtonPanelProps = {
|
| 110 |
handle_action: (selected: string | null) => void;
|
| 111 |
likeable: boolean;
|
|
|
|
| 123 |
dispatch: any;
|
| 124 |
current_feedback: string | null;
|
| 125 |
watermark: string | null;
|
| 126 |
+
file: FileData | null;
|
| 127 |
+
show_download_button: boolean;
|
| 128 |
+
show_share_button: boolean;
|
| 129 |
};
|
| 130 |
|
| 131 |
let button_panel_props: ButtonPanelProps;
|
|
|
|
| 145 |
layout,
|
| 146 |
dispatch,
|
| 147 |
current_feedback,
|
| 148 |
+
watermark,
|
| 149 |
+
file: get_file(messages),
|
| 150 |
+
show_download_button: allow_file_downloads,
|
| 151 |
+
show_share_button: true
|
| 152 |
};
|
| 153 |
</script>
|
| 154 |
|
|
|
|
| 278 |
.message {
|
| 279 |
position: relative;
|
| 280 |
width: 100%;
|
|
|
|
| 281 |
}
|
| 282 |
|
| 283 |
.message.display_consecutive_in_same_bubble {
|
| 284 |
margin-top: 0;
|
| 285 |
}
|
| 286 |
|
| 287 |
+
.message + .message {
|
| 288 |
+
margin-top: var(--spacing-sm);
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
/* avatar styles */
|
| 292 |
.avatar-container {
|
| 293 |
flex-shrink: 0;
|